#include<bits/stdc++.h>
using namespace std;
int main(){
long long a;
cin>>a;
if(a==1){
for(int b=1;b<=a;b++){
cout<<" "<<b<<endl;
}
}
if(a==2){
for(int b=1;b<=a;b++){
for(int c=1;c<=a;c++){
if(b!=c){
cout<<" "<<b<<" "<<c<<endl;
}
}
}
}
if(a==3){
for(int b=1;b<=a;b++){
for(int c=1;c<=a;c++){
for(int d=1;d<=a;d++){
if(b!=c&&b!=d&&c!=d&&c!=d){
cout<<" "<<b<<" "<<c<<" "<<d<<endl;
}
}
}
}
}
if(a==4){
for(int b=1;b<=a;b++){
for(int c=1;c<=a;c++){
for(int d=1;d<=a;d++){
for(int e=1;e<=a;e++){
if(b!=c&&b!=d&&b!=e&&c!=d&&c!=d&&c!=e&&d!=e){
cout<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;
}
}
}
}
}
}
if(a==5){
for(int b=1;b<=a;b++){
for(int c=1;c<=a;c++){
for(int d=1;d<=a;d++){
for(int e=1;e<=a;e++){
for(int f=1;f<=a;f++){
if(b!=c&&b!=d&&b!=e&&b!=f&&c!=d&&c!=d&&c!=e&&c!=f&&d!=e&&d!=f&&e!=f){
cout<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<endl;
}
}
}
}
}
}
}
if(a==6){
for(int b=1;b<=a;b++){
for(int c=1;c<=a;c++){
for(int d=1;d<=a;d++){
for(int e=1;e<=a;e++){
for(int f=1;f<=a;f++){
for(int g=1;g<=a;g++){
if(b!=c&&b!=d&&b!=e&&b!=f&&b!=g&&c!=d&&c!=d&&c!=e&&c!=f&&c!=g&&d!=e&&d!=f&&d!=g&&e!=f&&e!=g&&f!=g){
cout<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" "<<g<<endl;
}
}
}
}
}
}
}
}
if(a==7){
for(int b=1;b<=a;b++){
for(int c=1;c<=a;c++){
for(int d=1;d<=a;d++){
for(int e=1;e<=a;e++){
for(int f=1;f<=a;f++) {
for(int g=1;g<=a;g++){
for(int h=1;h<=a;h++){
if(b!=c&&b!=d&&b!=e&&b!=f&&b!=g&&b!=h&&c!=d&&c!=d&&c!=e&&c!=f&&c!=g&&c!=h&&d!=e&&d!=f&&d!=g&&d!=h&&e!=f&&e!=g&&e!=h&&f!=g&&f!=h&&g!=h&&g!=h){
cout<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" "<<g<<" "<<h<<endl;
}
}
}
}
}
}
}
}
}
if(a==8){
for(int b=1;b<=a;b++){
for(int c=1;c<=a;c++){
for(int d=1;d<=a;d++){
for(int e=1;e<=a;e++){
for(int f=1;f<=a;f++){
for(int g=1;g<=a;g++){
for(int h=1;h<=a;h++){
for(int i=1;i<=a;i++){
if(b!=c&&b!=d&&b!=e&&b!=f&&b!=g&&b!=h&&b!=i&&c!=d&&c!=d&&c!=e&&c!=f&&c!=g&&c!=h&&c!=i&&d!=e&&d!=f&&d!=g&&d!=h&&d!=i&&e!=f&&e!=g&&e!=h&&e!=i&&f!=g&&f!=h&&f!=i&&g!=h&&g!=h&&g!=i&&h!=i){
cout<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" "<<g<<" "<<h<<" "<<i<<endl;
}
}
}
}
}
}
}
}
}
}
if(a==9){
for(int b=1;b<=a;b++){
for(int c=1;c<=a;c++){
for(int d=1;d<=a;d++){
for(int e=1;e<=a;e++){
for(int f=1;f<=a;f++){
for(int g=1;g<=a;g++){
for(int h=1;h<=a;h++){
for(int i=1;i<=a;i++){
for(int j=1;j<=a;j++){
if(b!=c&&b!=d&&b!=e&&b!=f&&b!=g&&b!=h&&b!=i&&b!=j&&c!=d&&c!=d&&c!=e&&c!=f&&c!=g&&c!=h&&c!=i&&c!=j&&d!=e&&d!=f&&d!=g&&d!=h&&d!=i&&d!=j&&e!=f&&e!=g&&e!=h&&e!=i&&e!=j&&f!=g&&f!=h&&f!=i&&f!=j&&g!=h&&g!=h&&g!=i&&g!=j&&h!=i&&h!=j&&i!=j){
cout<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" "<<g<<" "<<h<<" "<<i<<" "<<j<<endl;
}
}
}
}
}
}
}
}
}
}
}
return 0;
}