var
t,i,j,l,b:longint;
s:string;
a:char;
function useless(x:longint):boolean;
begin
if (((s[x]='t') or (s[x]='T')) and ((s[x+1]='h')or (s[x+1]='H')) and ((s[x+2]='e') or (s[x+2]='E')))
or (((s[x]='a') or (s[x]='A')) and ((s[x+1]='n') or (s[x+1]='N')) and ((s[x+2]='d') or (s[x+2]='D')))
or (((s[x]='f') or (s[x]='F')) and ((s[x+1]='o') or (s[x+1]='O')) and ((s[x+2]='r') or (s[x+2]='R')))
then exit(true) else exit(false);
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);j:=2;a:=s[1];b:=1;s:=s+' ';
while j<=length(s)+1 do
begin
if s[j-1]=' ' then begin a:=s[j];b:=j;inc(j);end else
if s[j]=' ' then
begin
l:=j-b;
if l<3 then inc(j) else
if l=3 then begin if useless(b) then inc(j)
else begin a:=upcase(a);write(a);inc(j);end;end
else begin a:=upcase(a);write(a);inc(j);end;
end
else inc(j);
end;
writeln;
end;
close(input);close(output);
end.