var
a,b:array[1..1000]of string;t,i,j,c,m,n,c1:longint;s:string;z:char;begin assign(input,'abbreviation.in');assign(output,'abbreviation.out');reset(input);rewrite(output); readln(t); for i:=1 to t do readln(a[i]);for i:=1 to t do begin s:='';c:=ord(a[i,0]); m:=0; for j:=1 to c+1 do begin if z=' ' then begins:='';m:=0;a[i]:=a[i]+z; end; z:=a[i,j]; if z<>' ' then begin s:=s+z; inc(m);end;if (m>=3)and(s<>'and')and(s<>'for')and(s<>'the')and(z=' ')and(s<>'The')and(s<>'For')and(s<>'And') then if (ord(s[1])>=65)and(ord(s[1])<=90) then b[i]:=b[i]+s[1] else b[i]:=b[i]+chr(ord(s[1])-32);end;end;for i:=1 to t do writeln(b[i]);close(input);close(output); end.