#include<bits/stdc++.h>

using namespace std;

int mapData[10][10];

int image[3][5][5] = {
	/*Small*/
	{ { 0, 0, 1, 0, 0 },
	  { 0, 1, 1, 1, 0 },
	  { 0, 0, 1, 0, 0 } },
	//*midium*/
	{ { 0, 0, 1, 1, 1 },
	  { 0, 0, 1, 1, 1 },
	  { 0, 0, 1, 1, 1 } },
	/*large*/
	{ { 0, 0, 1, 0, 0 },
	  { 0, 1, 1, 1, 0 },
	  { 1, 1, 1, 1, 1 },
	  { 0, 1, 1, 1, 0 },
	  { 0, 0, 1, 0, 0 } },
};

bool checkImage(int y, int x, int num) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			if (mapData[y + i][x - 2 + j] - image[num][i][j] < 0) {
				return false;
			}
		}
	}
	return true;
}

void paint(int y, int x, int num) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			mapData[y + i][x - 2 + j] -= image[num][i][j];
		}
	}
}

void repaint(int y, int x, int num) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			mapData[y + i][x - 2 + j] += image[num][i][j];
		}
	}
}

bool solve(int y, int x, int n) {
	if (n < 0) {
		return false;
	}
	if (y == 10) {
		return n == 0;
	}

	if (mapData[y][x] == 0) {
		y = y + (x == 9);
		x = (x + 1) % 10;
		return solve(y, x, n);
	}

	for (int image = 0; image < 3; image++) {
		if (!checkImage(y, x, image)) {
			continue;
		}
		paint(y, x, image);
		if (solve(y, x, n - 1)) {
			cout << x + (image == 1) << " " << y + 1 + (image == 2) << " " << image + 1 << endl;
			return true;
		}
		repaint(y, x, image);
	}
	return false;
}

int main() {
	int N;

	cin >> N;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> mapData[i][j];
		}
	}
	solve(0, 0, N);

	return 0;
}
