program letter;
var
w:array [1..100] of string;
l,k,n,i,j:integer;
tmp:string;
begin
assign (input,'letter.in');
reset (input);
readln (n);
for i:=1 to n do readln (w[i]);
close (input);
assign (output,'letter.out');
rewrite (output);
for i:=1 to n-1 do for j:=i+1 to n do if w[i]>w[j] then begin
tmp:=w[i];
w[i]:=w[j];
w[j]:=tmp;
end;
i:=1;
while i<=n do begin
j:=i;while (j<=n) and (w[i][1]=w[j][1]) do inc(j);dec(j);
for k:=i to j-1 do for l:=i+1 to j do if (length(w[k])>length(w[l])) then begin
tmp:=w[i];
w[i]:=w[j];
w[j]:=tmp;
end;
i:=j+1;
end;
for i:=1 to n do writeln (w[i]);
close (output);
end.