var
s,ss,sss:string;
ch:char;
t,i,j:longint;
function change(s:string):char;
begin
if (length(s)>=3) then
if (s<>'AND')and(s<>'FOR')and(s<>'THE') then
exit(s[1]);
exit(' ');
end;
begin
assign(input,'abbreviation.in');reset(input);
assign(output,'abbreviation.out');rewrite(output);
readln(t);
for i:=1 to t do begin
readln(sss);
j:=1;
while j<=length(sss) do begin
ch:=sss[j];
while ch<>' ' do begin
ss:=ss+ch;
inc(j);
if j>length(sss) then break;
ch:=sss[j];
end;
inc(j);
ss:=upcase(ss);
if change(ss)<>' ' then s:=s+change(ss);
ss:='';
end;
writeln(s);
s:='';
end;
close(input);
close(output);
end.