#include<cstdio>
#include<cstring>
using namespace std;
const bool simp[]= {0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0};
bool use[11];
int s[11];
int len=0,step;
void search(int step)
{
if(step==11)
{
if(simp[s[1]+s[10]])
{
for(int i=1;i!=11;i++)
printf("%d ",s[i]);
printf("\n");
}
}else
{
for(int i=2;i!=11;i++)
if(!use[i]&&simp[s[step-1]+i])
{
use[i]=1;
s[step]=i;
search(step+1);
use[i]=0;
}
}
}
int main()
{
freopen("output.txt","w",stdout);
memset(use,0,sizeof(use));
use[1]=1;
s[1]=1;
search(2);
return 0;
}