#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
#define int long long
#define str string
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
ll gcm(ll i, ll j) {//?????§??¬?´???°
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int a[10][10], h = 10, w = 10, n;
int u[2][4] = { {0,0,1,-1},{-1,1,0,0} };
bool io(int i, int j, int z) {
	return i - z >= 0 && i + z < h&&j + z < w&&j - z >= 0;
}
bool s(int i, int j) {
	if (!io(i, j, 1))
		return 0;
	for (int z = 0; z < 4; z++)
		if (!a[i + u[0][z]][j + u[1][z]])
			return 0;
	return 1;
}
bool m(int i, int j) {
	if (s(i, j) && a[i - 1][j - 1] && a[i - 1][j + 1] && a[i + 1][j - 1] && a[i + 1][j + 1])
		return 1;
	return 0;
}
bool b(int i, int j) {
	if (!io(i, j, 2)) return 0;
	if (m(i, j) && a[i - 2][j] && a[i + 2][j] && a[i][j - 2] && a[i][j + 2])
		return 1;
	return 0;
}
struct A {
	int x, y, s;
};
vector<A>ans;
void s2(int i, int j) {
	a[i][j]--; a[i - 1][j]--; a[i + 1][j]--; a[i][j + 1]--; a[i][j - 1]--;
}
void s3(int i, int j) {
	a[i][j]++; a[i - 1][j]++; a[i + 1][j]++; a[i][j + 1]++; a[i][j - 1]++;
}
void m2(int i, int j) {
	s2(i, j);
	a[i - 1][j - 1]--; a[i - 1][j + 1]--; a[i + 1][j - 1]--; a[i + 1][j + 1]--;
}
void m3(int i, int j) {
	s3(i, j);
	a[i - 1][j - 1]++; a[i - 1][j + 1]++; a[i + 1][j - 1]++; a[i + 1][j + 1]++;
}
bool k = 0;
void solve(int p, int sum) {
	if (k) return;
	if (p == n) {
		if (sum == 0) 
			k = 1;
		else
			return;
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j]) {
				if (s(i,j)) {
					s2(i, j);
					ans.push_back(A{ i,j,1 });
					solve(p + 1, sum - 5);if (k) return;
					ans.pop_back();
					s3(i, j);
				}
				if (m(i,j)) {
					m2(i, j);
					ans.push_back(A{ i,j,2 });
					solve(p + 1, sum - 9);if (k)return;
					ans.pop_back();
					m3(i, j);
				}
				if (b(i, j)) {
					m2(i, j);
					a[i - 2][j]--; a[i + 2][j]--; a[i][j - 2]--; a[i][j + 2]--;
					ans.push_back(A{ i,j,3 });
					solve(p + 1, sum - 13);if (k)return;
					ans.pop_back();
					m3(i, j);
					a[i - 2][j]++; a[i + 2][j]++; a[i][j - 2]++; a[i][j + 2]++;
				}
			}
		}
	}
}
signed main() {
	cin >> n;
	int sum = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			sum += a[i][j];
		}
	solve(0, sum);
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i].y << " " << ans[i].x << " " << ans[i].s << endl;
	}
	getchar(); getchar();
}