#include <iostream>
using namespace std;
int main()
{
int n;
int Break=0;
long long int res,res1,res2,res3,res4,rank,diff;
long long int b_left,b_ryt,t_left,t_ryt;
while(cin>>n)
{
res=1;
res1=1;
res2=1;
res3=1;
res4=1;
Break=0;
if(n==1)
{
cout<<7<<";"<<8<<";"<<9<<";\n";
cout<<6<<";"<<1<<";"<<2<<";\n";
cout<<5<<";"<<4<<";"<<3<<";\n";
continue;
}
for(long long int i=0;i<1500000000;i++)
{
if(Break)
break;
res1+=i*2;
if(res1>=n)
{
rank=i;
res=res1;
Break=1;
//continue;
}
res2+=i*4;
if(res2>=n)
{
rank=i;
res=res2;
Break=1;
//continue;
}
res3+=i*6;
if(res3>=n)
{
rank=i;
res=res3;
Break=1;
//continue;
}
res4+=i*8;
if(res4>=n)
{
rank=i;
res=res4;
Break=1;
}
}
if(rank==0)
{
cout<<7<<";"<<8<<";"<<9<<";\n";
cout<<6<<";"<<1<<";"<<2<<";\n";
cout<<5<<";"<<4<<";"<<3<<";\n";
continue;
}
diff=rank*2;
t_ryt=res;
t_left=t_ryt-diff;
b_left=t_left-diff;
b_ryt=b_left-diff;
if(n==t_ryt)
{
cout<<res+(rank+1)*8-2<<";"<<res+(rank+1)*8-1<<";"<<res+(rank+1)*8<<";\n";
cout<<res-1<<";"<<res<<";"<<res+1<<";\n";
cout<<res-(rank)*8<<";"<<(res+1)-(rank)*8<<";"<<res+2<<";\n";
continue;
}
if(n==t_left)
{
cout<<res+(rank+1)*6<<";"<<res+(rank+1)*6+1<<";"<<res+2+(rank+1)*6<<";\n";
cout<<res-1+(rank+1)*6<<";"<<n<<";"<<n+1<<";\n";
cout<<res-2+(rank+1)*6<<";"<<n-1<<";"<<n-rank*6-(rank-1)*2<<";\n";
continue;
}
if(n==b_left)
{
//cout<<rank<<"\n";
cout<<res+2+(rank+1)*4<<";"<<n+1<<";"<<n-(2*rank-1)*4<<";\n";
cout<<res+1+(rank+1)*4<<";"<<n<<";"<<n-1<<";\n";
cout<<res+(rank+1)*4<<";"<<res+(rank+1)*4-1<<";"<<res+(rank+1)*4-2<<";\n";
continue;
}
if(n==b_ryt)
{
cout<<res-rank*8-(rank-1)*6<<";"<<n-1<<";"<<(res+(rank+1)*2)-2<<";\n";
cout<<n+1<<";"<<n<<";"<<(res+(rank+1)*2)-1<<";\n";
cout<<(res+(rank+1)*2)+2<<";"<<(res+(rank+1)*2)+1<<";"<<res+(rank+1)*2<<";\n";
continue;
}
if(n>b_ryt && n<b_left)
{
if(n==4)
{
cout<<6<<";"<<1<<";"<<2<<";\n";
cout<<5<<";"<<4<<";"<<3<<";\n";
cout<<16<<";"<<15<<";"<<14<<";\n";
continue;
}
int prev_b_ryt=res-rank*8-(rank-1)*6;
int prev_b_left=b_left-(2*rank-1)*4;
int next_b_ryt=res+(rank+1)*2;
int next_b_left=res+(rank+1)*4;
int pos= n- b_ryt;
if(pos==1)
{
cout<<prev_b_ryt+(pos)<<";"<<prev_b_ryt+(pos-1)<<";"<<n-2<<";\n";
cout<<n+1<<";"<<n<<";"<<n-1<<";\n";
cout<<next_b_ryt+pos+2<<";"<<next_b_ryt+pos+1<<";"<<next_b_ryt+pos<<";\n";
continue;
}
if(b_left-n==1)
{
cout<<n+2<<";"<<prev_b_ryt+(pos-1)<<";"<<prev_b_ryt+(pos-2)<<";\n";
cout<<n+1<<";"<<n<<";"<<n-1<<";\n";
cout<<next_b_ryt+pos+2<<";"<<next_b_ryt+pos+1<<";"<<next_b_ryt+pos<<";\n";
continue;
}
cout<<prev_b_ryt+(pos)<<";"<<prev_b_ryt+(pos-1)<<";"<<prev_b_ryt+(pos-2)<<";\n";
cout<<n+1<<";"<<n<<";"<<n-1<<";\n";
cout<<next_b_ryt+pos+2<<";"<<next_b_ryt+pos+1<<";"<<next_b_ryt+pos<<";\n";
continue;
}
if(n<t_ryt && n>t_left)
{
if(n==8)
{
cout<<22<<";"<<23<<";"<<24<<";\n";
cout<<7<<";"<<8<<";"<<9<<";\n";
cout<<6<<";"<<1<<";"<<2<<";\n";
continue;
}
int prev_t_left=t_left-rank*6-(rank-1)*2;
int prev_t_ryt=res-(rank)*8;
int next_t_ryt=res+(rank+1)*8;
int next_t_left=res+(rank+1)*6;
int pos= n- t_left;
if(pos==1)
{
cout<<next_t_left+pos<<";"<<next_t_left+pos+1<<";"<<next_t_left+pos+2<<";\n";
cout<<n-1<<";"<<n<<";"<<n+1<<";\n";
cout<<n-2<<";"<<prev_t_left<<";"<<prev_t_left+1<<";\n";
continue;
}
{
cout<<next_t_left+pos<<";"<<next_t_left+pos+1<<";"<<next_t_left+pos+2<<";\n";
cout<<n-1<<";"<<n<<";"<<n+1<<";\n";
cout<<prev_t_left+(pos-2)<<";"<<prev_t_left+(pos-1)<<";"<<prev_t_left+pos<<";\n";
continue;
}
}
if(n>b_left && n<t_left)
{
if(n==6)
{
cout<<20<<";"<<7<<";"<<8<<";\n";
cout<<19<<";"<<6<<";"<<1<<";\n";
cout<<18<<";"<<5<<";"<<4<<";\n";
continue;
}
int prev_t_left=t_left-rank*6-(rank-1)*2;
int prev_b_left=b_left-(2*rank-1)*4;
int next_b_left=res+(rank+1)*4;
int next_t_left=res+(rank+1)*6;
int pos= n- b_left;
if(pos==1)
{
cout<<next_b_left+pos+2<<";"<<n+1<<";"<<prev_b_left+(pos)<<";\n";
cout<<next_b_left+pos+1<<";"<<n<<";"<<prev_b_left+(pos-1)<<";\n";
cout<<next_b_left+pos<<";"<<n-1<<";"<<n-2<<";\n";
continue;
}
if(n==t_left-1)
{
cout<<next_b_left+pos+2<<";"<<n+1<<";"<<n+2<<";\n";
cout<<next_b_left+pos+1<<";"<<n<<";"<<prev_b_left+(pos-1)<<";\n";
cout<<next_b_left+pos<<";"<<n-1<<";"<<prev_b_left+(pos-2)<<";\n";
continue;
}
cout<<next_b_left+pos+2<<";"<<n+1<<";"<<prev_b_left+(pos)<<";\n";
cout<<next_b_left+pos+1<<";"<<n<<";"<<prev_b_left+(pos-1)<<";\n";
cout<<next_b_left+pos<<";"<<n-1<<";"<<prev_b_left+(pos-2)<<";\n";
continue;
}
if(n<b_ryt)
{
if(n==2)
{
cout<<8<<";"<<9<<";"<<10<<";\n";
cout<<1<<";"<<2<<";"<<11<<";\n";
cout<<4<<";"<<3<<";"<<12<<";\n";
continue;
}
int prev_t_ryt=res-(rank)*8;
int prev_b_ryt=res-rank*8-(rank-1)*6;
int next_b_ryt=res+(rank+1)*2;
int next_t_ryt=res+(rank+1)*8;
int pos= b_ryt - n;
if(pos==1)
{
cout<<prev_b_ryt-pos<<";"<<n-1<<";"<<next_b_ryt-(pos+2)<<";\n";
cout<<prev_b_ryt<<";"<<n<<";"<<next_b_ryt-(pos+1)<<";\n";
cout<<n+2<<";"<<n+1<<";"<<next_b_ryt-(pos)<<";\n";
continue;
}
if(prev_t_ryt+1==n)
{
cout<<res-1<<";"<<res<<";"<<res+1<<";\n";
cout<<n-1<<";"<<n<<";"<<res+2<<";\n";
cout<<prev_b_ryt-(pos-2)<<";"<<n+1<<";"<<res+3<<";\n";
continue;
}
if(prev_t_ryt+2==n)
{
cout<<n-2<<";"<<n-1<<";"<<res+2<<";\n";
cout<<prev_b_ryt-(pos-1)<<";"<<n<<";"<<res+3<<";\n";
cout<<prev_b_ryt-(pos-1)+1<<";"<<n+1<<";"<<res+4<<";\n";
continue;
}
cout<<prev_b_ryt-pos<<";"<<n-1<<";"<<next_b_ryt-(pos+2)<<";\n";
cout<<prev_b_ryt-pos+1<<";"<<n<<";"<<next_b_ryt-(pos+1)<<";\n";
cout<<prev_b_ryt-pos+2<<";"<<n+1<<";"<<next_b_ryt-(pos)<<";\n";
continue;
}
}
return 0;
}