var
s:string;
i,n,w:longint;
function can(x:longint):boolean;
var
q:string;
begin
if x<3 then exit(false)
else if x>3 then exit(true)
else
begin
q:=copy(s,1,3);
q:=upcase(q);
if (q='THE')or(q='FOR')or(q='AND') then exit(false);
exit(true);
end;
end;
begin
assign(input,'abbreviation.in');reset(input);
assign(output,'abbreviation.out');rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(s);
w:=pos(' ',s);
while (length(s)<>0) do
begin
if can(w-1) then write(upcase(s[1]));
delete(s,1,w);
w:=pos(' ',s);
if w=0 then w:=length(s)+1;
end;
writeln
end;
close(input);
close(output);
end.