var
n, i, j, s : integer;
ss, m, max : longint;
a : array [1..8, 1..8] of integer;
p, pmax : array [0..8] of integer;
f1, f2 : text;
begin
assign(f1,'input.txt'); reset(f1);
assign(f2,'output.txt'); rewrite(f2);
readln(f1,n); ss:=0;
for i:=1 to n do
for j:=1 to n do
begin read(f1,s); ss:=ss+s; a[i,j]:=s end;
for i:=0 to n do p[i]:=i;
max:=0;
repeat
m:=0; for i:=1 to n do m:=m+a[i,p[i]];
if m>max then begin max:=m; pmax:=p end;
j:=n; repeat j:=j-1 until p[j]<p[j+1];
if j>0 then
begin
i:=n+1; repeat i:=i-1 until p[i]>p[j];
s:=p[i]; p[i]:=p[j]; p[j]:=s;
for i:=j+1 to (n+j+1) div 2 do
begin s:=p[i]; p[i]:=p[n+j+1-i]; p[n+j+1-i]:=s end
end
until j=0;
for i:=1 to n do write(f2,chr(pmax[i]-1+ord('A')));
writeln(f2);
write(f2,ss-max);
close(f2)
end.
var
n, i, j, s : integer;
ss, m, max : longint;
a : array [1..8, 1..8] of integer;
p, pmax : array [0..8] of integer;
f1, f2 : text;
begin
assign(f1,'input.txt'); reset(f1);
assign(f2,'output.txt'); rewrite(f2);
readln(f1,n); ss:=0;
for i:=1 to n do
for j:=1 to n do
begin read(f1,s); ss:=ss+s; a[i,j]:=s end;
for i:=0 to n do p[i]:=i;
max:=0;
repeat
m:=0; for i:=1 to n do m:=m+a[i,p[i]];
if m>max then begin max:=m; pmax:=p end;
j:=n; repeat j:=j-1 until p[j]<p[j+1];
if j>0 then
begin
i:=n+1; repeat i:=i-1 until p[i]>p[j];
s:=p[i]; p[i]:=p[j]; p[j]:=s;
for i:=j+1 to (n+j+1) div 2 do
begin s:=p[i]; p[i]:=p[n+j+1-i]; p[n+j+1-i]:=s end
end
until j=0;
for i:=1 to n do write(f2,chr(pmax[i]-1+ord('A')));
writeln(f2);
write(f2,ss-max);
close(f2)
end.