type
data=record
name:string;
papernum:integer;
paper:array[1..100] of integer;
zhishu:integer;
end;
var
a:array[1..101] of data;
b:array[1..100] of string;
c:array[1..100] of integer;
i,n,j,zjs,tempn,h,k:integer;
temps:string;
tempch:char;
begin
assign(input,'publish.in'); assign(output,'publish.out');
reset(input); rewrite(output);
readln(n);
for i:=1 to n do
readln(b[i]);
for i:=1 to n do
begin
j:=1;
while j<=n do
begin
read(tempch);
if (tempch='0') or (tempch='1') then begin c[j]:=c[j]+ord(tempch)-48; inc(j) end;
end;
end;
for i:=1 to n do
for j:=1 to 100 do
with a[j] do
begin
if name='' then begin name:=b[i]; inc(papernum); inc(zjs); paper[papernum]:=c[i]; break end else
if b[i]=name then begin inc(papernum); paper[papernum]:=c[i]; break; end;
end;
for i:=1 to zjs do
begin
h:=1;
j:=1;
while j>=h do
begin
j:=0;
for k:=1 to a[i].papernum do
if a[i].paper[k]>=h then inc(j);
if j>=h then inc(h);
end;
a[i].zhishu:=h-1;
end;
for i:=1 to zjs do
for j:=i+1 to zjs do
if a[i].zhishu<a[j].zhishu then begin a[101]:=a[i]; a[i]:=a[j]; a[j]:=a[101]; end else
if a[i].zhishu=a[j].zhishu then
if a[i].name>a[j].name then begin a[101]:=a[i]; a[i]:=a[j]; a[j]:=a[101]; end;
for i:=1 to zjs do
writeln(a[i].name,' ',a[i].zhishu);
end.