#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;cin >> n;
int a[10];
for (int i=0;i<n;i++)
{
a[i]=i+1;
printf("%5d",a[i]);
}
cout << endl;
while (next_permutation(a,a+n))
{
for (int i=0;i<n;i++) printf("%5d",a[i]);
cout << endl;
}
return 0;
}