#include<bits/stdc++.h>
using namespace std;
int n, ans[25], flag[25], noi[25];
void dfs(int dep)
{
if(dep > n)
{
int pos1, pos2, pos3;
for(int i = 1; i <= n; i ++)
{
cout << ans[i] << " ";
noi[i] = ans[i];
if(noi[i] == 1) pos1 = i;
if(noi[i] == 2) pos2 = i;
if(noi[i] == 3) pos3 = i;
}
cout << "\n";
cout << "//" << pos1 << " " << pos2 << " " << pos3 << "//\n";
cout << "->";
if(pos3 != 1) swap(noi[pos3], noi[pos3 - 1]);
for(int i = 1; i <= n; i ++)
{
if(noi[i] == 1) pos1 = i;
if(noi[i] == 2) pos2 = i;
if(noi[i] == 3) pos3 = i;
}
if(pos1 != 3) swap(noi[pos1], noi[pos1 + 1]);
for(int i = 1; i <= n; i ++)
{
if(noi[i] == 1) pos1 = i;
if(noi[i] == 2) pos2 = i;
if(noi[i] == 3) pos3 = i;
}
if(pos2 != 1) swap(noi[pos2], noi[pos2 - 1]);
for(int i = 1; i <= n; i ++)
cout << noi[i] << " ";
cout << "\n";
return;
}
for(int i = 1; i <= n; i ++)
{
if(flag[i] == 1) continue;
ans[dep] = i;
flag[i] = 1;
dfs(dep + 1);
flag[i] = 0;
}
}
int main()
{
//杯子是1, 勺子是2, 筷子是3;
cin >> n;
dfs(1);
return 0;
}