program fl;
var
a,b,c,d,n,l,t,l2,k,j:longint;
s,s2,s0,sx,sj:string;
h:char;
begin
assign(input,'abbreviation.in');
reset(input);
assign(output,'abbreviation.out');
rewrite(output);
read(n); readln;
for a:=1 to n do
begin
read(s);readln; s:=s+' '; sx:=s+' ';
l:=length(sx);
t:=1; s0:=s2;
repeat
begin
while (h<>' ') do
begin l2:=l2+1; h:=s[l2];
if s[l2]<>' ' then s2:=s2+s[l2]; end;
if (s2<>'for') and (s2<>'For') then
if (s2<>'and') and (s2<>'And') then
if (s2 <>'the') and (s2<>'The') then
if length(s2)>2 then
begin
if (s2[1]>='A') and (s2[1]<='Z') then write(s2[1])
else write(chr(ord(s2[1])-32));
end;
s:=sj;
for b:=l2+1 to l do s:=s+sx[b];
l:=l-l2; l2:=0; s2:=sj; sx:=s; h:='a';
end;
until l=0;
writeln;
end;
close(input);
close(output);
end.