#include <iostream>
#include <cstdio>
#include <cstring>
#define N 25
using namespace std;
int n;
int path[N];
int st[N];
int primes[40] = // 因为数据范围不太大,判断素数又比较麻烦,因此采用打表的方式以空间换时间
{
0, 0, 1, 1, 0,
1, 0, 1, 0, 0,
0, 1, 0, 1, 0,
0, 0, 1, 0, 1,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0
};
bool check(int a, int b)
{
if(!((a + b) & 1)) return false; // 如果和为偶数则一定不是(一定不会出现1 + 1的情况)
return primes[a + b];
}
void dfs(int u)
{
if(u == n + 1) // 如果搜到了最后一个位置的下一个位置
{
if(check(path[u - 1], path[1])) // 检查首尾
{
for (int i = 1; i <= n; i ++) // 输出路径
{
printf("%d", path[i]);
if(i <= n - 1) printf(" ");
else puts("");
}
}
return;
}
for(int i = 2; i <= n; i ++) // 从2开始遍历
{
if(!st[i] && check(path[u - 1], i))
{
st[i] = true;
path[u] = i;
dfs(u + 1);
st[i] = false;
}
}
}
int main()
{
int cnt = 0;
while(cin >> n)
{
printf("Case %d:\n", ++ cnt);
if(n % 2) // 如果输入为奇数,由于必须以1开头,首尾相加一定为大于2的偶数(非质数)
{
puts("");
continue;
}
memset(path, 0, sizeof path);
memset(st, 0, sizeof st);
path[1] = 1;
st[1] = 1;
dfs(2);
puts("");
}
return 0;
}