program abbreviation;
const
infile = 'abbreviation.in';
outfile = 'abbreviation.out';
var
t,i,j,flag,x,k:longint;
s,sx:string;
begin
assign(input,infile);reset(input);
assign(output,outfile);rewrite(output);
readln(t);
x:=0;
for i:=1 to t do begin
readln(s);
flag:=0;
insert(' ',s,1);
s[length(s)+1]:=' ';
s[0]:=chr(ord(s[0])+1);
s:=upcase(s);
for j:=1 to length(s) do begin
if s[j]<>' ' then inc(flag);
if ((flag<3)or((s[j-3]=' ')and(((s[j-2]='A')and(s[j-1]='N')and(s[j]='D'))or((s[j-2]='F')and(s[j-1]='O')and(s[j]='R'))or((s[j-2]='T')and(s[j-1]='H')and(s[j]='E')))))and(s[j+1]=' ') then flag:=0;
if (flag>=3)and(s[j+1]=' ') then begin
inc(x);
sx[x]:=s[j-flag+1];
flag:=0;
end;
end;
for k:=1 to x do write(sx[k]);
writeln;
x:=0;
end;
close(input);close(output);
end.