#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>

#include <vector>
#include <stack>
#include <queue>
#include <random>
#include <cstdlib>
#include <cmath>
#include <sstream>

using namespace std;

int small[][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
};
pair<int, int> smallCenter = { 0,1 };

int middle[][5]{
	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
};
pair<int, int> middleCenter = { 1,1 };

int big[][5]{
	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
};
pair<int, int> bigCenter = { 1,2 };

pair<pair<int, int>, int> point[12];
int table[10][10];

bool clearCheck() {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (table[i][j] != 0) return false;
		}
	}
	return true;
}
bool removeCheck(int y, int x, int drop[][5]) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			if (!drop[i][j]) continue;
			if (x + j - 2 < 0 || x + j - 2 >= 10) return false;
			if (y + i < 0 || y + i >= 10) return false;
			if (!table[y + i][x + j - 2]) return false;
		}
	}
	return true;
}

void remove(int y, int x, int drop[][5]) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			table[y + i][x + j - 2] -= drop[i][j];
		}
	}
}

void add(int y, int x, int drop[][5]) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			table[y + i][x + j - 2] += drop[i][j];
		}
	}
}

bool rec(int i, int j, int c) {
	if (c < 0) return clearCheck();
	while (!(i == 10)) {
		if (table[i][j]) {
			if (removeCheck(i, j, small)) {
				point[c] = make_pair(make_pair(i + smallCenter.second, j + smallCenter.first), 1);
				remove(i, j, small);
				if (rec(i, j, c - 1)) return true;
				add(i, j, small);
			}

			if (removeCheck(i, j, middle)) {
				point[c] = make_pair(make_pair(i + middleCenter.second, j + middleCenter.first), 2);
				remove(i, j, middle);
				if (rec(i, j, c - 1)) return true;
				add(i, j, middle);
			}

			if (removeCheck(i, j, big)) {
				point[c] = make_pair(make_pair(i + bigCenter.second, j + bigCenter.first), 3);
				remove(i, j, big);
				if (rec(i, j, c - 1)) return true;
				add(i, j, big);
			}
		}
		j++;
		i += j / 10;
		j = j % 10;
	}
	return false;
}
void q91() {
	int n;
	for (; cin >> n;) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				cin >> table[i][j];
			}
		}
		rec(0, 0, n - 1);
		for (int i = 0; i < n; i++) {
			cout << point[i].first.second << " " << point[i].first.first << " " << point[i].second << endl;
		}
	}
}

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