const n=4; m=8;
var a:array[1..n,1..m] of integer;
i,j,x: integer;
begin
x:=1;
for j:=1 to m do
begin
for i:=1 to n do
begin
a[i,j]:=x;
if (j mod 2 = 0) and (i<>n) then x:=x-1
else x:=x+1
end;
x:=x+n-1
end;
for i:=1 to n do
begin
for j:=1 to m do write(a[i,j]:5);
writeln
end
end.