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);
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')and(a[j+2]='e')then w:=false;
if ((a[j]='A')or(a[j]='a'))and(a[j+1]='n')and(a[j+2]='d')then w:=false;
if ((a[j]='F')or(a[j]='f'))and(a[j+1]='o')and(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.