program P932;
const
q:array[1..3] of string=('and','for','the');
var
a:array[1..200] of string;
c:char;
i,j,k,l,m,n,t:longint;
w,sum,u:string;
function find(w:string):boolean;
begin
for k:=1 to length(w) do
w[k]:=lowercase(w[k]);
if (w='and')or(w='for')or(w='the') then
exit(true) else exit(false);
end;
begin
assign(input,'abbreviation.in');
reset(input);
assign(output,'abbreviation.out');
rewrite(output);
readln(t);
for j:=1 to t do
begin
readln(w);
w:=w+' ';
for i:=1 to length(w) do
if w[i]=' ' then
begin
if (length(u)>2)and(not(find(u))) then
begin c:=upcase(u[1]); sum:=sum+c; end;
u:='';
end
else u:=u+w[i];
writeln(sum);
sum:='';
end;
end.