#include<iostream>
#include<memory.h>
using namespace std;
int result[30];
int a[5][6];
int flag;
int count;
int p[8]={-2,-1,-2,-1,1,2,1,2};
int q[8]={-1,-2, 1, 2,-2,-1,2,1};
void print()
{
for(int i=0;i<30;i++)
cout<<result[i]<<" ";
cout<<endl;
}
bool panduan(int row,int col)
{
if(row>=0&&row<=4&&col>=0&&col<=5&&a[row][col]==0)
return true;
else
return false;
}
void dfs(int row,int col,int count)
{
result[count]=6*row+col+1;
if(count==29)
{
flag=1;
return;
}
else
{
for(int i=0;i<8;i++)
{
if(panduan(row+p[i],col+q[i]))
{
a[row+p[i]][col+q[i]]=1;
dfs(row+p[i],col+q[i],count+1);
}
}
if(result[count+1]==0)
{
a[row][col]=0;
result[count]=0;
}
return;
}
}
int main()
{
int n;
while(cin>>n&&n!=-1)
{
int row=(n-1)/6;
int col=(n-1)%6;
int count=0;
flag=0;
memset(a,0,sizeof(a));
memset(result,0,sizeof(result));
a[row][col]=1;
dfs(row,col,count);
if(flag==1)
print();
}
return 0;
}