program oxoxo;
var
s:string;
a:string;
n:longint;
i,j:longint;
begin
assign(input,'abbreviation.in');
reset(input);
assign(output,'abbreviation.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(a);
for j:=1 to length(a) do
if a[j]in['a'..'z'] then a[j]:=chr(ord(a[j])-32);
a:=a+' '; j:=0;
repeat
s:='';
if (a[j]=' ') or (j=0) then
repeat
inc(j);
s:=s+a[j];
until a[j]=' ';
delete(s,length(s),1);
if (length(s)>=3)and(s<>'AND')and(s<>'FOR')and(s<>'THE')
then write(s[1]);
until j=length(a);
if i<>n then writeln;
end;
close(input);
close(output);
end.