var
t,i:longint;
function isalpha_s(a:char):boolean;begin
if (a<='z') and (a>='a') then exit(true) else exit(false);
end;
function isalpha_b(a:char):boolean;begin
if (a<='Z') and (a>='A') then exit(true) else exit(false);
end;
function isalpha(a:char):boolean;begin
if isalpha_b(a) or isalpha_s(a) then exit(true) else exit(false);
end;
procedure upper(var a:string);
var i:integer;begin
for i:=1 to length(a) do
if isalpha_s(a[i]) then a[i]:=chr(ord(a[i])-32);
end;
procedure work;
var s,word:string;i:longint;begin
readln(s);
upper(s);
s:=s+' ';
i:=0;
word:='';
while i<length(s) do begin
inc(i);
if isalpha(s[i]) then word:=word+s[i] else begin
if (word<>'THE') and (word<>'AND') and (word<>'FOR') and( length(word)>=3) then
write(word[1]);
word:='';
end;
end;
writeln;
end;
begin
assign(input,'abbreviation.in');reset(input);
assign(output,'abbreviation.out');rewrite(output);
readln(t);for i:=1 to t do work();
close(input);close(output);
end.