#include<iostream>
#include<string.h>
using namespace std;
int n;
int a[1025][1025];
struct place
{
int x, y;
};
void solution(place start, place end);
int main(void)
{
int k;
cin >> k;
n = 1 << k;
int x, y;
cin >> x >> y;
memset(a, 0, sizeof(a));
a[x][y] = 1;
place start, end;
start.x = 1;
start.y = 1;
end.x = n;
end.y = n;
solution(start, end);
return 0;
}
void solution(place start, place end)
{
place mid;
mid.x = (start.x + end.x) / 2;
mid.y = (start.y + end.y) / 2;
int p = 0, q = 0;
for (int i = start.x; i <= end.x; i++)
{
for (int j = start.y; j <= end.y; j++)
{
if (a[i][j] != 0)
{
p = i;
q = j;
break;
}
}if (p)break;
}
if (start.x + 1 == end.x)
{
if (p == end.x)
{
if (q == end.y)
{
a[p][q - 1] = 4;
a[p - 1][q] = 4;
a[p - 1][q - 1] = 4;
cout << p << " " << q - 1 << " " << 4 << endl;
cout << p - 1 << " " << q << " " << 4 << endl;
cout << p - 1 << " " << q - 1 << " " << 4 << endl;
return;
}
else if (q == start.y)
{
a[p][q + 1] = 3;
a[p - 1][q] = 3;
a[p - 1][q + 1] = 3;
cout << p << " " << q + 1 << " " << 3 << endl;
cout << p - 1 << " " << q << " " << 3 << endl;
cout << p - 1 << " " << q - 1 << " " << 3 << endl;
return;
}
}
else if (p == start.x)
{
if (q == end.y)
{
a[p][q - 1] = 2;
a[p + 1][q] = 2;
a[p + 1][q - 1] = 2;
cout << p << " " << q - 1 << " " << 2 << endl;
cout << p + 1 << " " << q << " " << 2 << endl;
cout << p + 1 << " " << q - 1 << " " << 2 << endl;
return;
}
else if (q == start.y)
{
a[p][q + 1] = 1;
a[p + 1][q] = 1;
a[p + 1][q + 1] = 1;
cout << p << " " << q - 1 << " " << 1 << endl;
cout << p + 1 << " " << q << " " << 1 << endl;
cout << p + 1 << " " << q - 1 << " " << 1 << endl;
return;
}
}
}
if (p <= mid.x)
{
if (q <= mid.y)
{
a[mid.x][mid.y + 1] = 1;
a[mid.x + 1][mid.y] = 1;
a[mid.x + 1][mid.y + 1] = 1;
cout << mid.x << " " << mid.y + 1 << " " << 1 << endl;
cout << mid.x + 1 << " " << mid.y << " " << 1 << endl;
cout << mid.x + 1 << " " << mid.y + 1 << " " << 1 << endl;
place lust, luend, rust, ruend, ldst, ldend, rdst, rdend;
lust.x = start.x;
lust.y = start.y;
luend.x = mid.x;
luend.y = mid.y;
rust.x = start.x;
rust.y = mid.x + 1;
ruend.x = mid.x;
ruend.y = end.y;
ldst.x = mid.x + 1;
ldst.y = start.y;
ldend.x = end.x;
ldend.y = mid.y;
rdst.x = mid.x + 1;
rdst.y = mid.y + 1;
rdend.x = end.x;
rdend.y = end.y;
solution(lust, luend);
solution(rust, ruend);
solution(ldst, ldend);
solution(rdst, rdend);
}
else if (q>mid.y)
{
place s, e;
s.x = start.x;
s.y = mid.y;
e.x = mid.x;
e.y = end.y;
a[mid.x][mid.y] = 2;
a[mid.x + 1][mid.y] = 2;
a[mid.x + 1][mid.y + 1] = 2;
cout << mid.x << " " << mid.y << " " << 2 << endl;
cout << mid.x + 1 << " " << mid.y << " " << 2 << endl;
cout << mid.x + 1 << " " << mid.y + 1 << " " << 2 << endl;
place lust, luend, rust, ruend, ldst, ldend, rdst, rdend;
lust.x = start.x;
lust.y = start.y;
luend.x = mid.x;
luend.y = mid.y;
rust.x = start.x;
rust.y = mid.y + 1;
ruend.x = mid.x;
ruend.y = end.y;
ldst.x = mid.x + 1;
ldst.y = start.y;
ldend.x = end.x;
ldend.y = mid.y;
rdst.x = mid.x + 1;
rdst.y = mid.y + 1;
rdend.x = end.x;
rdend.y = end.y;
solution(lust, luend);
solution(rust, ruend);
solution(ldst, ldend);
solution(rdst, rdend);
}
}
else if (p>mid.x)
{
if (q <= mid.y)
{
place s, e;
s.x = mid.x;
s.y = start.y;
e.x = mid.x;
e.y = mid.y;
a[mid.x][mid.y] = 3;
a[mid.x][mid.y + 1] = 3;
a[mid.x + 1][mid.y + 1] = 3;
cout << mid.x << " " << mid.y << " " << 3 << endl;
cout << mid.x << " " << mid.y + 1 << " " << 3 << endl;
cout << mid.x + 1 << " " << mid.y + 1 << " " << 3 << endl;
place lust, luend, rust, ruend, ldst, ldend, rdst, rdend;
lust.x = start.x;
lust.y = start.y;
luend.x = mid.x;
luend.y = mid.y;
rust.x = start.x;
rust.y = mid.y + 1;
ruend.x = mid.x;
ruend.y = end.y;
ldst.x = mid.x + 1;
ldst.y = start.y;
ldend.x = end.x;
ldend.y = mid.y;
rdst.x = mid.x + 1;
rdst.y = mid.y + 1;
rdend.x = end.x;
rdend.y = end.y;
solution(lust, luend);
solution(rust, ruend);
solution(ldst, ldend);
solution(rdst, rdend);
}
else if (q>mid.y)
{
place s, e;
s.x = mid.x + 1;
s.y = start.y + 1;
e.x = end.x;
e.y = end.y;
a[mid.x][mid.y] = 4;
a[mid.x][mid.y + 1] = 4;
a[mid.x + 1][mid.y] = 4;
cout << mid.x << " " << mid.y << " " << 4 << endl;
cout << mid.x << " " << mid.y + 1 << " " << 4 << endl;
cout << mid.x + 1 << " " << mid.y << " " << 4 << endl;
place lust, luend, rust, ruend, ldst, ldend, rdst, rdend;
lust.x = start.x;
lust.y = start.y;
luend.x = mid.x;
luend.y = mid.y;
rust.x = start.x;
rust.y = mid.x + 1;
ruend.x = mid.x;
ruend.y = end.y;
ldst.x = mid.x + 1;
ldst.y = start.y;
ldend.x = end.x;
ldend.y = mid.y;
rdst.x = mid.x + 1;
rdst.y = mid.y + 1;
rdend.x = end.x;
rdend.y = end.y;
solution(lust, luend);
solution(rust, ruend);
solution(ldst, ldend);
solution(rdst, rdend);
}
}
}