#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <random>
#include <cstdlib>

using namespace std;

#define R 10
#define PSIZE 5
//????????????????????????14*14????????????????????£????????????????????????
//??¢?´¢?????§????????????????????§?????????
//??¨?????£????????????????????????????????????????????????????????????????????£??????
int T[10][10];
int N;

//????????????????????¨???????????????????????????????????¶??????????????????????????????????????´
//?????´????????????center??§???????????´
int mid = (PSIZE - 1) / 2;
int p[3][5][5] = {
	{0,0,1,0,0,
	0,1,1,1,0,
	0,0,1,0,0,
	0,0,0,0,0,
	0,0,0,0,0},

	{0,0,1,1,1,
	0,0,1,1,1,
	0,0,1,1,1,
	0,0,0,0,0,
	0,0,0,0,0},

	{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}

};
//{2,0}???????????????????????????
int center[3][2] = { {0,1},{1,1},{0,2} };
int psize[] = { 3,3,5 };

void add_point(int x, int y, int point[5][5]) {
	for (int i = 0; i < PSIZE; i++) {
		for (int j = 0; j < PSIZE; j++) {
			if (point[i][j]) T[y + i][x + j - mid] += point[i][j];
		}
	}
}

void delete_point(int x, int y, int point[5][5]) {
	for (int i = 0; i < PSIZE; i++) {
		for (int j = 0; j < PSIZE; j++) {
			if (point[i][j]) T[y + i][x + j - mid] -= point[i][j];
		}
	}
}

bool can_delete(int x, int y, int point[5][5]) {
	for (int i = 0; i < PSIZE; i++) {
		for (int j = 0; j < PSIZE; j++) {
			if (y + i < 0 || y + i >= R ||
				x + j - mid < 0 || x + j - mid >= R)
				if (point[i][j]) return false;
			if (T[y + i][x + j - mid] - point[i][j] < 0) return false;
		}
	}
	return true;
}

bool checkT() {
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < R; j++) {
			if (T[i][j] != 0) return false;
		}
	}
	return true;
}

vector<pair< pair<int, int>, int> > points;
bool rec(int x, int y, int cnt) {
	if (checkT()) return true;
	if (cnt == N) return false;

	for (; !T[y][x];) {
		y += (x == 9 ? 1 : 0);
		x = (x + 1) % 10;
		if (y == 10) return false;
	}

	for (int i = 0; i < 3; i++) {
		if (!can_delete(x, y, p[i])) continue;
		delete_point(x, y, p[i]);
		points.push_back(make_pair(make_pair(x + center[i][0], y + center[i][1]), i));
		if (rec(x, y, cnt + 1)) return true;
		points.pop_back();
		add_point(x, y, p[i]);
	}
	return false;
}

void q91() {
	cin >> N;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < R; j++) {
			cin >> T[i][j];
		}
	}
	bool ans = rec(0, 0, 0);
	for (auto it = points.begin(); it != points.end(); it++) {
		cout << (*it).first.first << " " << (*it).first.second << " " << (*it).second + 1 << endl;
	}

}

int main() {
	q91();
	return 0;
}