#include <bits/stdc++.h>
using namespace std;
const int N=50;
int g[N];
bool st[N];
int n;
void dfs(int x){
if(x>n){//最后一个位置也选完
for(int i=1;i<=n;i++){
printf("%5d ",g[i] );
}
printf("\n");
}
for(int i=1;i<=n;i++){//这个位置能选几
if(!st[i]){//未被选过
g[x]=i;//选择
st[i]=1;
dfs(x+1);//进入下一个位置
g[x]=0;
st[i]=0;
}
}
}
int main(){
scanf("%d",&n);
dfs(1);
return 0;
}