var
i,j,n,p,k:integer;
s:string;
a:array[0..1000] of string;
begin
assign(input,'abbreviation.in');
reset(input);
assign(output,'abbreviation.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(a[i]);
p:=length(a[i]);
j:=0;k:=0;
repeat
k:=k+1;
j:=j+1;
if (ord(a[i][j])<=122) and (ord(a[i][j])>=97) then
a[i][j]:=chr(ord(a[i][j])-32);
if (a[i][j]=' ')or(k=p) then
begin
if a[i][j]=' ' then s:=copy(a[i],1,j-1);
if k=p then s:=copy(a[i],1,j);
delete(a[i],1,j);j:=0;
if (length(s)>2) and (s<>'AND') and(s<>'FOR') and (s<>'THE') THEN
write(s[1]);
end;
until k=p;
writeln;
end;
close(input);
close(output);
end.