#include<iostream>
#include<queue>
#include<vector>
#include<tuple>
using namespace std;
vector<vector<int>>S;
vector<vector<int>> solve(vector<vector<int>>p, int x, int y, int r) {
	if (r == 1) { p[x][y]--; p[x + 1][y]--; p[x - 1][y]--; p[x][y - 1]--; p[x][y + 1]--; }
	if (r == 2) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; }
	if (r == 3) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; p[x + 2][y]--; p[x][y + 2]--; p[x - 2][y]--; p[x][y - 2]--; }
	return p;
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < 10; i++) { vector<int>V(10, 0); S.push_back(V); }
	vector<vector<int>>START = S; int SUM = 0;
	for (int i = 0; i < 10; i++)for (int j = 0; j < 10; j++) { cin >> S[i][j]; SUM += S[i][j]; }
	queue<tuple<vector<vector<int>>, int, vector<tuple<int, int, int>>, int>> Q;
	vector<tuple<int, int, int>>ZERO;
	Q.push(make_tuple(S, 0, ZERO, SUM));

	while (!Q.empty()) {
		vector<vector<int>>a1 = get<0>(Q.front()); int a2 = get<1>(Q.front());
		vector<tuple<int, int, int>>a3 = get<2>(Q.front()); int a4 = get<3>(Q.front()); Q.pop();
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };

		for (int i = 1; i <= 3; i++) {
			int rem1 = a4 - P[i], rem2 = n - (a2 + 1); bool OK = true;
			if (rem2 == 0) {
				if (rem1 != 0)OK = false;
			}
			else if ((1.0*rem1 / rem2 < 4.99) || (1.0*rem1 / rem2) > 13.01)OK = false;
			if (OK == false)continue;
			int LIM = 0; if (a3.size() >= 1) LIM = get<0>(a3[a3.size() - 1]) * 10 + get<1>(a3[a3.size() - 1]);
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					int DD = j * 10 + k;
					if (DD < LIM) continue;
					vector<vector<int>>G = solve(a1, j, k, i);
					vector<tuple<int, int, int>>H = a3;
					for (int l = 0; l < 10; l++) {
						for (int m = 0; m < 10; m++) {
							if (G[l][m] < 0)goto F;
						}
					}
					H.push_back(make_tuple(j, k, i));
					if (G == START && a2 + 1 == n) {
						for (int j = 0; j < H.size(); j++) {
							cout << get<1>(H[j]) << ' ' << get<0>(H[j]) << ' ' << get<2>(H[j]) << endl;
						}
						goto E;
					}
					Q.push(make_tuple(G, a2 + 1, H, a4 - P[i]));
				F:;
				}
			}
		}
	}
E:;
	return 0;
}