#include<iostream>
using namespace std;
int pow_2[20]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096};
bool vst[1145][1145];
int k,x,y;
void f(int xx,int yy,int dir,int nk){
if(vst[xx][yy]==true) return;
if(nk<1) return;
int np=pow_2[nk-1];
if(dir==1){
int tx=xx+np,ty=yy+np;
if(vst[tx][ty]==true) return;
else vst[tx][ty]=true;
cout<<tx<<" "<<ty<<" "<<dir<<" "<<endl;
f(xx,yy,1,nk-1);
f(xx+np,yy,2,nk-1);
f(xx+np,yy+np,1,nk-1);
f(xx+np-1,yy+np,3,nk-1);
}
else if(dir==2){
int tx=xx+np,ty=yy+np-1;
if(vst[tx][ty]==true) return;
else vst[tx][ty]=true;
cout<<tx<<" "<<ty<<" "<<dir<<endl;
f(xx,yy,4,nk-1);
f(xx+np,yy,2,nk-1);
f(xx+np,yy+np,1,nk-1);
f(xx+np-1,yy+np,3,nk-1);
}
else if(dir==3){
int tx=xx+np-1,ty=yy+np;
if(vst[tx][ty]==true) return;
else vst[tx][ty]=true;
cout<<tx<<" "<<ty<<" "<<dir<<endl;
f(xx,yy,4,nk-1);
f(xx+np,yy,3,nk-1);
f(xx+np,yy+np,2,nk-1);
f(xx+np-1,yy+np,3,nk-1);
}
else {
int tx=xx+np-1,ty=yy+np-1;
if(vst[tx][ty]==true) return;
else vst[tx][ty]=true;
cout<<tx<<" "<<ty<<" "<<dir<<endl;
f(xx,yy,4,nk-1);
f(xx+np,yy,2,nk-1);
f(xx+np,yy+np,4,nk-1);
f(xx+np-1,yy+np,3,nk-1);
}
}
int main(){
cin>>k;
cin>>x>>y;
vst[x][y]=true;
int tmp1=pow_2[k],tmp2=pow_2[k-1];
if(x<=tmp2&&y<=tmp2) f(1,1,1,k);
else if(x<=tmp2&&y<=tmp1) f(1,1,2,k);
else if(x<=tmp1&&y<=tmp2) f(1,1,3,k);
else f(1,1,4,k);
return 0;
}