#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 27
using namespace std;
int n;
int a[MAX];
bool used[MAX];
bool p[MAX];
void init ( )
{
memset ( p , 0 , sizeof ( p ) );
p[2] = p[3] = p[5] = p[7] = p[11]
= p[13] = p[17] = p[19] = p[23]
= p[29] = p[31] = p[37] = 1;
}
void dfs ( int u = 1 , int h = 1 )
{
a[h] = u;
if ( h== n && !p[a[h]+a[1]] ) return;
if ( h == n )
{
for ( int i = 1 ; i < n ; i++ )
printf ( "%d " , a[i] );
printf ( "%d\n" , a[n] );
return;
}
for ( int i = 1 ; i <= n ; i++ )
{
if ( used[i] ) continue;
if ( !p[i+a[h]] ) continue;
used[i] = true;
dfs ( i , h+1 );
used[i] = false;
}
}
int main ( )
{
init ();
int c = 1;
while ( ~scanf ( "%d" , &n ) )
{
memset ( used , 0 , sizeof ( used ) );
printf ( "Case %d:\n" , c++ );
used[1] = true;
dfs ( );
puts ("");
}
}
11-02
11-02