#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <bitset>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef std::vector<int> vi;
typedef std::vector<pair<int, int> > vii;
//----------Main source code -----------------//
int n, ring[17];
bitset<32> prime;
bitset<17> state;
void rcr(int i){
if(i==n-1){
if(prime[1+ring[i-1]]){
cout<<ring[0];
for(int j=1;j<n-1;j++)
cout<<" "<<ring[j];
cout<<endl;
}
}
for(int j=2;j<n;j++)
if(state[j]&&prime[ring[i-1]+j]){
ring[i]=j;
state.reset(j);
rcr(i+1);
state.set(j);
}
}
int main() {
//-prime sieve-------
prime.set();
for(int i=2;i<32;i++)
if(prime[i])
for(int j=2*i;j<32;j+=i)
prime.reset(j);
int ca =1;
while(cin.good()&&cin>>n){
n++;
state.set();
ring[0]=1;
if(ca!=1) cout<<endl;
printf("Case %d:\n", ca++);
rcr(1);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPG1hdGguaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBzdGQ6OnZlY3RvcjxpbnQ+IHZpOwp0eXBlZGVmIHN0ZDo6dmVjdG9yPHBhaXI8aW50LCBpbnQ+ID4gdmlpOwovLy0tLS0tLS0tLS1NYWluIHNvdXJjZSBjb2RlIC0tLS0tLS0tLS0tLS0tLS0tLy8KaW50IG4sIHJpbmdbMTddOwpiaXRzZXQ8MzI+IHByaW1lOwpiaXRzZXQ8MTc+IHN0YXRlOwoKdm9pZCByY3IoaW50IGkpewoJaWYoaT09bi0xKXsKCQlpZihwcmltZVsxK3JpbmdbaS0xXV0pewoJCQljb3V0PDxyaW5nWzBdOwoJCQlmb3IoaW50IGo9MTtqPG4tMTtqKyspCgkJCQljb3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