program letter;
var
i,j:integer;
a:array[1..100] of string;
r,rr:string;
n,x:integer;
procedure panduan;
var
i,j,l,ll,lll,g:integer;
begin
l:=length(r);
ll:=length(rr);
x:=0;
g:=0;
if l>ll then lll:=ll else lll:=l;
for i:=1 to lll do
begin
if ord(r[i])<ord(rr[i]) then break;
if ord(r[i])>ord(rr[i]) then
begin
x:=1;
break;
end
else inc(g);
end;
if (g=lll) and (l>ll) then x:=1;
end;
begin
assign(input,'letter.in');
reset(input);
assign(output,'letter.out');
rewrite(output);
readln(n);
for i:=1 to n do
readln(a[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
begin
r:=a[i];
rr:=a[j];
panduan;
if x=1 then
begin
r:=a[i];
a[i]:=a[j];
a[j]:=r;
end;
end;
for i:=1 to n do writeln(a[i]);
close(input);
close(output);
end.