program p932;
var
t,i,j,n:integer;
s:array[0..999] of string;
k:char;
begin
assign(input,'abbreviation.in');
reset(input);
assign(output,'abbreviation.out');
rewrite(output);
readln(t);
for i:=1 to t do
readln(s[i]);
for i:=1 to t do
begin
if (ord(s[i][1])>=65)and(ord(s[i][1])<=90) then write(s[i][1])
else write(chr(ord(s[i][1])-32));
for j:=2 to length(s[i]) do
begin
for k:='A' to 'Z' do
if (s[i][j]=k)and(s[i][j-1]=' ') then write(k);
end;
writeln;
end;
end.
{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.}