#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char mat[20][20];
int ans[15];
int n;
bool ok(int x,int y)
{
int tx,ty;
int ans[15];
int temp=0;
tx=x;
while(tx>=0)
{
if(mat[tx][y]==1) return false;
if(y-temp>=0&&mat[tx][y-temp]==1) return false;
if(y+temp<n&&mat[tx][y+temp]==1) return false;
tx--;temp++;
}
return true;
}
void dfs(int x,int y)
{
if(ok(x,y))
{
if(x==n-1) {ans[n]++;return ;}
mat[x][y]=1;
for(int i=0;i<n;i++)
{
dfs(x+1,i);
}
mat[x][y]=0;
}
}
int main()
{
int i,j;
//memset(ans,0,sizeof(ans));
//while(scanf("%d",&n),n)
for(n=1;i<=10;n++)
{
memset(mat,0,sizeof(mat));
ans[n]=0;
for(i=0;i<n;i++)
{
dfs(0,i);
}
//printf("%d\n",ans);
}
while(scanf("%d",&n),n)
{
printf("%d\n",ans[n]);
}
return 0;
}