#include<iostream>
using namespace std;
int j=1;
class Queen{
friend void nQueen(int);
private:
bool Place(int k);
void Backtrack(int t);
int n,*x;
long sum;
};
bool Queen::Place(int k)
{
int j;
for(j=1;j<k;j++)
if((abs(k-j)==abs(x[j]-x[k]))||(x[j]==x[k])) return false;
return true;
}
void Queen::Backtrack(int t)
{
int i;
if(t>n){
cout<<"Case "<<j++<<":";
for(i=1;i<=n;i++)
cout<<" "<<x[i];
cout<<endl;
}
else for(i=1;i<=n;i++)
{
x[t]=i;
if(Place(t))Backtrack(t+1);
}
}
void nQueen(int n)
{
int i;
Queen X;
X.n=n;
X.sum=0;
int *p=new int [n+1];
for(i=0;i<=n;i++)
p[i]=0;
X.x=p;
X.Backtrack(1);
delete []p;
//return X.sum;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
nQueen(n);
}
return 0;
}