program magic;
var
a:array[1..16] of integer;
h:array[1..16] of boolean;
x,y:longint;
function pd:boolean;
begin
pd:=false;
if a[13]+a[14]+a[15]+a[16]<>34 then exit;
if a[1]+a[4]+a[13]+a[16]<>34 then exit;
if a[4]+a[8]+a[12]+a[16]<>34 then exit;
if a[1]+a[6]+a[11]+a[16]<>34 then exit;
if a[4]+a[7]+a[10]+a[13]<>34 then exit;
if a[3]+a[4]+a[7]+a[8]<>34 then exit;
if a[9]+a[10]+a[13]+a[14]<>34 then exit;
if a[11]+a[12]+a[15]+a[16]<>34 then exit;
pd:=true;
end;
procedure print;
var
i,j:longint;
begin
for i:=1 to 4 do
begin
for j:=1 to 4 do
write(a[(i-1)*4+j],' ');
writeln;
end;
writeln;
end;
procedure work(K:longint);
var
i,j,l:longint;
begin
case k of
1..3,5,7,9..10:begin
if a[k]<>1 then begin
for i:=2 to 16 do
if not h[i] then
begin
h[i]:=true;
a[k]:=i;
work(k+1);
a[k]:=0;
h[i]:=false;
end;
end
else work(k+1);
end;
4,8,12:begin
i:=a[k-1]+a[k-2]+a[k-3];
if a[k]=1 then begin
if i<>33 then exit
else work(k+1);
end
else
if (34-i>0)and(34-i<17) and not h[34-i] then begin
h[34-i]:=true;
a[k]:=34-i;
work(k+1);
a[k]:=0;
h[34-i]:=false;
end;
end;
6:begin
i:=a[5]+a[1]+a[2];
if a[k]=1 then begin
if i<>33 then exit
else work(k+1);
end
else if (34-i>0)and(34-i<17)and not h[34-i] then begin
h[34-i]:=true;
a[k]:=34-i;
work(k+1);
a[k]:=0;
h[34-i]:=false;
end;
end;
11:begin
i:=a[6]+a[7]+a[10];
if a[k]=1 then begin
if i<>33 then exit
else work(k+1);
end
else if (34-i>0)and(34-i<17)and not h[34-i] then begin
h[34-i]:=true;
a[k]:=34-i;
work(k+1);
a[k]:=0;
h[34-i]:=false;
end;
end;
13..16:begin
i:=a[k-12]+a[k-8]+a[k-4];
if a[k]=1 then begin
if i<>33 then exit
else work(k+1);
end
else if (34-i>0)and(34-i<17)and not h[34-i] then begin
h[34-i]:=true;
a[k]:=34-i;
work(k+1);
a[k]:=0;
h[34-i]:=false;
end;
end;
17:if pd then print;
end;
end;
begin
assign(input,'magic.in');
assign(output,'magic.out');
reset(input);
rewrite(output);
readln(x,y);a[(x-1)*4+y]:=1;
h[1]:=true;
work(1);
close(input);
close(output);
end.