#include <iostream>
#include <cstdio>
using namespace std;
int c,map[10][10];
bool used[20]={0,1},filled[10][10];
void printit(void)
{
if (c)
cout<<endl;
c++;
int i,j;
for (i=1;i<=4;i++)
for (j=1;j<=4;j++)
{
cout<<map[i][j];
if (j==4)
cout<<endl;
else
cout<<' ';
}
}
bool check(int x,int y)
{
if (filled[1][1]+filled[1][4]+filled[4][1]+filled[4][4]==4)
if (map[1][1]+map[1][4]+map[4][1]+map[4][4]!=34)
return(0);
if (filled[1][1]+filled[1][2]+filled[2][1]+filled[2][2]==4)
if (map[1][1]+map[1][2]+map[2][1]+map[2][2]!=34)
return(0);
if (filled[1][3]+filled[1][4]+filled[2][3]+filled[2][4]==4)
if (map[1][3]+map[1][4]+map[2][3]+map[2][4]!=34)
return(0);
if (filled[3][1]+filled[3][2]+filled[4][1]+filled[4][2]==4)
if (map[3][1]+map[3][2]+map[4][1]+map[4][2]!=34)
return(0);
if (filled[3][3]+filled[3][4]+filled[4][3]+filled[4][4]==4)
if (map[3][3]+map[3][4]+map[4][3]+map[4][4]!=34)
return(0);
if (filled[2][2]+filled[2][3]+filled[3][2]+filled[3][3]==4)
if (map[2][2]+map[2][3]+map[3][2]+map[3][3]!=34)
return(0);
if (filled[1][1]+filled[2][2]+filled[3][3]+filled[4][4]==4)
if (map[1][1]+map[2][2]+map[3][3]+map[4][4]!=34)
return(0);
if (filled[1][4]+filled[2][3]+filled[3][2]+filled[4][1]==4)
if (map[1][4]+map[2][3]+map[3][2]+map[4][1]!=34)
return(0);
int i;
for (i=1;i<=4;i++)
if (filled[i][1]+filled[i][2]+filled[i][3]+filled[i][4]==4)
if (map[i][1]+map[i][2]+map[i][3]+map[i][4]!=34)
return(0);
for (i=1;i<=4;i++)
if (filled[1][i]+filled[2][i]+filled[3][i]+filled[4][i]==4)
if (map[1][i]+map[2][i]+map[3][i]+map[4][i]!=34)
return(0);
return(1);
}
void tryit(int x,int y)
{
if (y>4)
{
x++;
y=1;
}
if (map[x][y]==1&&!(x==4&&y==4))
{
if (check(x,y))
tryit(x,y+1);
return;
}
int i;
if (x==4&&y==4)
{
if (map[x][y]==1)
{
if (check(x,y))
printit();
return;
}
for (i=1;i<=16;i++)
if (!used[i])
break;
map[x][y]=i;
if (check(x,y))
printit();
return;
}
filled[x][y]=true;
for (i=1;i<=16;i++)
{
if (used[i])
continue;
map[x][y]=i;
used[i]=true;
if (check(x,y))
tryit(x,y+1);
used[i]=false;
//map[x][y]=0;
}
filled[x][y]=false;
}
int main(void)
{
freopen("magic.in","r",stdin);
freopen("magic.out","w",stdout);
int x,y;
cin>>x>>y;
map[x][y]=1;
filled[x][y]=true;
tryit(1,1);
return(0);
}