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