program cch(input,output);
var
i,n,tot:integer;
f,b:array[0..200] of boolean;
a:array[1..100] of integer;
procedure sushu;
var
i,j:integer;
begin
for i:=2 to 200 do
begin
f[i]:=true;
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then
begin
f[i]:=false;
break;
end;
end;
end;
procedure search(k:integer);
var
i:integer;
begin
if k=tot+1 then
begin
for i:=1 to tot do
begin
write(a[i],' ');
if i mod n=0 then writeln;
end;
close(input); close(output);
halt;
end;
for i:=1 to tot do
if b[i] then
if (k mod n<>1)and(f[i+a[k-1]])or(k mod n =1) then
if (k>n)and(f[i+a[k-n]])or(k<=n) then
begin
a[k]:=i; b[i]:=false;
search(k+1);
b[i]:=true;
end;
end;
begin
assign(input,'tianshu.in');
assign(output,'tianshu.out');
reset(input);
rewrite(output);
readln(n);
tot:=n*n;
sushu;
for i:=1 to tot do b[i]:=true;
a[1]:=1; b[1]:=false;
search(2);
write('NO');
close(input); close(output);
end.