var
a:string;
t,i,j,k:integer;
d,e:char;
w:boolean;
begin
assign(input,'abbreviation.in');reset(input);
assign(output,'abbreviation.out');rewrite(output);
read(t);
j:=0;
for i:=1 to t do begin
readln;
read(a);
a[length(a)+1]:=' ';
j:=1;
while a[j]<>' ' do
begin
k:=j+1;
while a[k]<>' ' do inc(k);
if k-j<3 then w:=false;
if k-j>3 then w:=true;
if k-j=3 then
begin
w:=true;
if ((a[j]='T')or(a[j]='t'))and((a[j+1]='h')or(a[j+1]='H'))and((a[j+2]='e')or(a[j+2]='E'))then w:=false;
if ((a[j]='A')or(a[j]='a'))and((a[j+1]='n')or(a[j+1]='N'))and((a[j+2]='d')or(a[j+2]='D'))then w:=false;
if ((a[j]='F')or(a[j]='f'))and((a[j+1]='O')or(a[j+1]='o'))and((a[j+2]='r')or(a[j+2]='R'))then w:=false;
end;
if w then
if ord(a[j])>96 then write(chr(ord(a[j])-32))
else write(a[j]);
if k<length(a) then j:=k+1
else a[j]:=' ';
end;
writeln;
end;
close(input);
close(output);
end.