#include<bits/stdc++.h>
using namespace std;
int n,vis[20]={0,1},a[20]={0,1},cnt;
bool judg(int x){
for(int i=2;i<=sqrt(x);i++){
if(x % i == 0){
return false;
}
}
return true;
}
void dfs(int k){
if(k>n && judg(a[n]+a[1])){
for(int i=1;i<=n;i++){
if(i!=n) cout << a[i] << " ";
else cout << a[i];
}
cout << endl;
return;
}
for(int i=2;i<=n;i++){
if(vis[i] == 0){
if(judg(i+a[k-1])){
vis[i] = 1;
a[k] = i;
dfs(k+1);
vis[i] = 0;
}
}
}
}
int main(){
while(cin >> n){
cout << "Case " << ++cnt << ":" << endl;
dfs(2);
cout << endl;
}
return 0;
}