#include<stdio.h>
int a[100][100] = {0};
int tot;
int check(int n, int m)
{
if(a[n][m]==0)
return 1;
else
return 0;
}
int sb(int n, int m, int s, int I, int J)
{
int i, j, N, M;
if(s == n*m+1)
{
tot++;
printf(“%d\n”, tot);
for(N=0; N<n; N++)
{
for(M=0; M<m; M++)
printf(“%3d “, a[N][M]);
printf(“\n”);
}
}
else
{
if(s == 1)
{
for(i=0; i<n; i++)
for(j=0; j<m; j++)
{
a[i][j] = s;
sb(n, m, s+1, i, j);
a[i][j] = 0;
}
}
if(s>1)
{
for(i=0; i<n; i++)
for(j=0; j<m; j++)
{
if(((i==I+2)&&(j==J+1))||((i==I+2)&&(j==J-1))||
((i==I+1)&&(j==J+2))||((i==I-1)&&(j==J+2))||
((i==I-2)&&(j==J+1))||((i==I-2)&&(j==J-1))||
((i==I-1)&&(j==J-2))||((i==I+1)&&(j==J-2)))
if(check(i, j))
{
a[i][j] = s;
sb(n, m, s+1, i, j);
a[i][j] = 0;
}
}
}
}
}
int main()
{
int i, j, n, m;
while(scanf(“%d%d”, &n, &m)!=EOF && n!=0)
{
tot = 0;
sb(n, m, 1, 0, 0);
}
}