#include<iostream>
using namespace std;

bool used[21];
bool prim[41];
int a[21];
int n;

void Initprim()


{
int i;
for(i = 0;i <= 40;i++)

{
prim[i] = false;
}
prim[2] = prim[3] = prim[5] = prim[7] = true;
prim[11] = prim[13] = prim[17] = prim[19] = true;
prim[23] = prim[29] = prim[31] = prim[37] = true;
}//将40以内的素数标记出来

void Dfs(int k)


{
int i;
if(k > n)

{
if(prim[a[1] + a[n]])//如果头尾相加是素数,就可输出

{
cout<<a[1];
for(i = 2;i <= n;i++)

{
cout<<" "<<a[i];
}
cout<<endl;
}
}
else

{
for(i = 2;i <= n;i++)

{
if(!used[i] && prim[i + a[k -1]])

{
used[i] = true;
a[k] = i;
Dfs(k + 1);//一直深搜,
used[i] = false;
}
}
}
}

int main()


{
int cases = 1;
int i;
Initprim();
for(i = 1;i <= 20;i++)
used[i] = false;
used[1] = true;
a[1] = 1;
while(cin>>n)

{
cout<<"Case "<<cases++<<":"<<endl;
Dfs(2);
cout<<endl;
}
return 0;
}