var
i,n,k,j:integer;
s,ls:string;
begin
assign(input,'abbreviation.in');
reset(input);
assign(output,'abbreviation.out');
rewrite(output);
readln(k);
for j:=1 to k do
begin
readln(s);
s:=upcase(s);
n:=length(s);
i:=1;
while i<=n do
begin
while (s[i]<>' ') and (i<=n) do
begin
ls:=ls+s[i];
i:=i+1;
end;
if length(ls)>=3 then
if (ls<>'AND') and (ls<>'THE') and (ls<>'FOR') then
write(ls[1]);
ls:='';
i:=i+1;
end;
writeln;
ls:='';
end;
close(input);
close(output);
end.