#include <bits/stdc++.h>
using namespace std;
using ll = long long;
queue <int> q13,q14,q15,q16,q18;
ll used=0;
void build12(int l, int r){
for (int i=l; i<=r; i++){
cout<<i<<' ';
}
cout<<"\n";
}
void build13(int sm){
for (int j=0; j<13; j++){
for (int i=0; i<12; i++){
int x=q13.front();
cout<<x+used<<' ';
q13.pop();
q13.push(x);
}
cout<<"\n";
}
}
void build14(int sm){
for (int j=0; j<7; j++){
for (int i=0; i<12; i++){
int x=q14.front();
cout<<x+used<<' ';
q14.pop();
q14.push(x);
}
cout<<"\n";
}
}
void build15(int sm){
for (int j=0; j<5; j++){
for (int i=0; i<12; i++){
int x=q15.front();
cout<<x+used<<' ';
q15.pop();
q15.push(x);
}
cout<<"\n";
}
}
void build16(int sm){
for (int j=0; j<4; j++){
for (int i=0; i<12; i++){
int x=q16.front();
cout<<x+used<<' ';
q16.pop();
q16.push(x);
}
cout<<"\n";
}
}
void build18(int sm){
for (int j=0; j<3; j++){
for (int i=0; i<12; i++){
int x=q18.front();
cout<<x+used<<' ';
q18.pop();
q18.push(x);
}
cout<<"\n";
}
}
void buildbit0(int sm){
vector <ll> v28[8]={
{0,1},
{2,3},
{4,5},
{6,7},
{8,9},
{10,11},
{12,13},
{14,15}
};
vector<int> mask = {1,1,1,1,1,1,0,0};
sort(mask.begin(), mask.end());
do {
vector<int> comb;
for (int i=0; i<8; i++){
if (mask[i]) comb.push_back(i);
}
for (int x : comb) cout<<v28[x][0]+used<<" "<<v28[x][1]+used<<" ";
cout << "\n";
} while (next_permutation(mask.begin(), mask.end()));
}
void buildbit1(int sm){
vector <ll> v18[6]={
{0,1,2},
{3,4,5},
{6,7,8},
{9,10,11},
{12,13,14},
{15,16,17}
};
vector<int> mask = {1,1,1,1,0,0};
sort(mask.begin(), mask.end());
do {
vector<int> comb;
for (int i=0; i<6; i++){
if (mask[i]) comb.push_back(i);
}
for (int x : comb) cout<<v18[x][0]+used<<" "<<v18[x][1]+used<<" "<<v18[x][2]+used<<" ";;
cout << "\n";
} while (next_permutation(mask.begin(), mask.end()));
}
void buildbit2(int sm){
vector <ll> v18[7]={
{0,1,2},
{3,4,5},
{6,7,8},
{9,10,11},
{12,13,14},
{15,16,17},
{18,19,20}
};
vector<int> mask = {1,1,1,1,0,0,0};
sort(mask.begin(), mask.end());
do {
vector<int> comb;
for (int i=0; i<7; i++){
if (mask[i]) comb.push_back(i);
}
for (int x : comb) cout<<v18[x][0]+used<<" "<<v18[x][1]+used<<" "<<v18[x][2]+used<<" ";;
cout << "\n";
} while (next_permutation(mask.begin(), mask.end()));
}
int main(){
ll n,x=1;
cin>>n;
for (int i=0; i<=12; i++){q13.push(i);}
for (int i=0; i<=13; i++){q14.push(i);}
for (int i=0; i<=14; i++){q15.push(i);}
for (int i=0; i<=15; i++){q16.push(i);}
for (int i=0; i<=17; i++){q18.push(i);}
// (1,12) (3,18) (4,16) (5,15) (7,14) (13,13)
vector <ll> arr[50] = {
{1},
{1,1},
{3},
{4},
{5},
{1,5},
{7},
{1,7},
{4,5},
{5,5},
{4,7},
{5,7},
{13},
{1,13},
{1,1,13},
{3,13},
{4,13},
{5,13},
{1,5,13},
{7,13},
{1,7,13},
{4,5,13},
{5,5,13},
{4,7,13},
{5,7,13},
{13,13},
{1,13,13},
{1,1,13,13},
{3,13,13},
{4,13,13},
{5,13,13},
{4,0},
{7,13,13},
{1,5,0},
{7,0},
{1,7,0},
{4,5,0},
{5,5,0},
{13,13,13},
{5,7,0},
{13,0},
{1,13,0},
{0,-1},
{1,0,-1},
{4,13,0},
{5,13,0},
{4,0,-1},
{7,13,0},
{1,13,-2},
{7,0,-1},
};
// (1,12) (3,18) (4,16) (5,15) (7,14) (13,13)
n--;
for (int i=0; i<arr[n].size(); i++){
if (arr[n][i]==1){build12(used,used+11);used=used+12;}
if (arr[n][i]==3){build18(0);used=used+18;}
if (arr[n][i]==4){build16(0);used=used+16;}
if (arr[n][i]==5){build15(0);used=used+15;}
if (arr[n][i]==7){build14(0);used=used+14;}
if (arr[n][i]==13){build13(0);used=used+13;}
if (arr[n][i]==0){buildbit0(0);used=used+16;}
if (arr[n][i]==-1){buildbit1(0);used=used+18;}
if (arr[n][i]==-2){buildbit2(0);used=used+21;}
}
}