#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
template <class Type>
void Swap(Type &A,Type &B){
Type t=A;
A=B;
B=t;
}
template <class Type>
void Perm(Type list[],int k,int m){
if(k==m){
for(int i=0;i<=m;i++){
cout<<setw(5)<<list[i];
}
cout<<endl;
}
else{
for(int i=k;i<=m;i++){
Swap(list[i],list[k]);
Perm(list,k+1,m);
Swap(list[i],list[k]);
}
}
}
int main(){
int x;
// cout<<"Please input a number:"<<endl;
cin>>x;
if(!((x>=1)&&(x<=9))){
cout<<"again"<<endl;
cin>>x;
}
vector<int> list(x);
for (int i=0;i<x;i++)
list[i]=i+1;
Perm(list.data(),0,x-1);
}