#include <vector>
#include <iostream>
using namespace std;
const int s = 10;
const vector<vector<int> > dx = {
	{ 0, 1, 1, 1, 2 },
	{ 0, 0, 0, 1, 1, 1, 2, 2, 2 },
	{ 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4 }
};
const vector<vector<int> > dy = {
	{ 0, -1, 0, 1, 0 },
	{ 0, 1, 2, 0, 1, 2, 0, 1, 2 },
	{ 0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0 }
};
const vector<int> augx = { 1, 1, 2 };
const vector<int> augy = { 0, 1, 0 };
int n, a[14][14], x[18], y[18], t[18];
bool solve(int cx, int cy, int cnt) {
	if (cx == s - 2) return (cnt == n);
	if (a[cx][cy] == 0) return solve(cy + 1 == s ? cx + 1 : cx, cy + 1 == s ? 0 : cy + 1, cnt);
	x[cnt] = cx, y[cnt] = cy;
	for (int i = 0; i < 3; ++i) {
		t[cnt] = i;
		bool ok = true;
		for (int j = 0; j < dx[i].size() && ok; ++j) {
			int tx = cx + dx[i][j], ty = cy + dy[i][j];
			if (tx < 0 || s <= tx || ty < 0 || s <= ty || a[tx][ty] == 0) ok = false;
		}
		if (!ok) continue;
		for (int j = 0; j < dx[i].size() && ok; ++j) {
			--a[cx + dx[i][j]][cy + dy[i][j]];
		}
		if (solve(cx, cy, cnt + 1)) return true;
		for (int j = 0; j < dx[i].size() && ok; ++j) {
			++a[cx + dx[i][j]][cy + dy[i][j]];
		}
	}
	return false;
}
int main() {
	cin >> n;
	for (int i = 0; i < s; ++i) {
		for (int j = 0; j < s; ++j) {
			cin >> a[i][j];
		}
	}
	solve(0, 0, 0);
	for (int i = 0; i < n; ++i) {
		cout << y[i] + augy[t[i]] << ' ' << x[i] + augx[t[i]] << ' ' << t[i] + 1 << '\n';
	}
	return 0;
}
