var
s,word:string;
t,i,j:longint;
function delete_s(sub:string):boolean;
var a:longint;
begin
a:=pos(sub,s);
if a<>0 then begin delete(s,a,length(sub));exit(true);end;
exit(false);
end;
function isalpha(a:char):boolean;
begin
if ( (ord(a)<=90) and (ord(a)>=65) ) or ( (ord(a)>=97) and (ord(a)<=122) )
then exit(true) else exit(false);
end;
function upper(a:char):char;
begin
if (ord(a)<=122) and (ord(a)>=97) then exit(chr(ord(a)-32)) else exit(a);
end;
begin
assign(input,'abbreviation.in');reset(input);
assign(output,'abbreviation.out');rewrite(output);
readln(t);
for i:=1 to t do
begin
readln(s);
while delete_s('for ') do ;
while delete_s(' for') do ;
while delete_s('and ') do ;
while delete_s(' and') do ;
while delete_s('the ') do ;
while delete_s(' the') do ;
while delete_s('For ') do ;
while delete_s(' For') do ;
while delete_s('And ') do ;
while delete_s(' And') do ;
while delete_s('The ') do ;
while delete_s(' The') do ;
while delete_s('FOR ') do ;
while delete_s(' FOR') do ;
while delete_s('AND ') do ;
while delete_s(' AND') do ;
while delete_s('THE ') do ;
while delete_s(' THE') do ;
j:=0;
word:='';
s:=s+',';
while j<length(s) do
begin
inc(j);
if isalpha(s[j]) then
begin
word:=word+s[j];
end
else
begin
if length(word)>=3 then write(upper(word[1]));
word:='';
end;
end;
writeln;
end;
close(input);
close(output);
end.