Var
st:array[1..200]of string;
n,i,j:longint;
gt:string;
function sl(st:string):longint;
var i,s:longint;
begin
s:=0;
for i:=1 to length(st) do if st[i] in ['0'..'9'] then inc(s);
sl:=s;
end;
Begin
readln(n);
for i:=1 to n do readln(st[i]);
for i:=1 to n -1 do
for j:=i+1 to n do
if sl(st[i]) > sl(st[j]) then
begin
gt:=st[i];
st[i]:=st[j];
st[j]:=gt;
end;
for i:=1 to n do writeln(st[i]);
readln;
end.