program letter;
var
sz:array[0..100]of string;
i,j,n:integer;
function change(s1,s2:string):integer;
var
i,l,p:integer;
begin
if length(s1)<length(s2) then l:=length(s1) else l:=length(s2);
p:=0;
for i:=1 to l do
begin
if ord(s1[i])>ord(s2[i]) then begin
p:=1;
break;
end;
if ord(s2[i])>ord(s1[i]) then break;
end;
if p=0 then if length(s1)>length(s2) then
if copy(s1,1,l)=s2 then p:=1;
change:=p;
end;
begin
assign(input,'letter.in');
assign(output,'letter.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
readln(sz[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if change(sz[i],sz[j])=1 then begin
sz[0]:=sz[i];
sz[i]:=sz[j];
sz[j]:=sz[0];
end;
end;
for i:=1 to n do
writeln(sz[i]);
close(input);
close(output);
end.