var
a,b,c,d,e,f,i,j,o,m,n:longint;
k:array[0..10000]of string;
s,l:string;
begin
assign(input,'abbreviation.in');
assign(output,'abbreviation.out');
reset(input);
rewrite(output);
readln(n);
for a:=1 to n do
readln(k[a]);
for a:=1 to n do
begin
b:=length(k[a]);
s:=k[a];
for c:=1 to b do
begin
if (c=1)or(ord(s[c-1])=32) then
begin
j:=0;
for i:=c to b do
if ord(s[i])=32 then
break
else
begin
j:=j+1;
l[j]:=s[i];
end;
if j>=3 then
begin
f:=0;
if ((l[1]='A')or(l[1]='a'))and(l[2]='n')and(l[3]='d') then
f:=1;
if ((l[1]='T')or(l[1]='t'))and(l[2]='h')and(l[3]='e') then
f:=1;
if ((l[1]='F')or(l[1]='f'))and(l[2]='o')and(l[3]='r') then
f:=1;
if f=0 then
if (ord(s[c])>96)and(ord(s[c])<123) then
write(chr(ord(s[c])-32))
else
write(s[c]);
end;
end;
end;
writeln;
end;
close(input);
close(output);
end.