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