#include <bits/stdc++.h>
using namespace std;

const int dx[] = {0, -1, 0, 1, 0, -1, -1, 1, 1, -2, 0, 2, 0};
const int dy[] = {0, 0, -1, 0, 1, 1, -1, -1, 1, 0, -2, 0, 2};
const int size[] = {5, 9, 13};

typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef tuple<int, int, int> T;

bool ingrid(int i, int j)
{
	return i >= 0 && i < 10 && j >= 0 && j < 10;
}

set<VVi> done;

vector<T> search(int n, VVi& grid)
{
	if (done.count(grid)) return vector<T>(0);
	
	if (!n){
		int f = 0;
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				f |= grid[i][j];
			}
		}
		vector<T> t;
		if (!f) t.push_back(T(-1, -1, -1));
		return t;
	}
	
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			for (int s = 0; s < 3; s++){
				bool f = false;
				for (int d = 0; d < size[s]; d++){
					if (!ingrid(i + dx[d], j + dy[d])) continue;
					if (--grid[i + dx[d]][j + dy[d]] < 0){
						f = true;
					}
				}
				if (!f){
					vector<T> tmp = search(n - 1, grid);
					if (tmp.size()){
						tmp.push_back(T(i, j, s));
						return tmp;
					}
				}
				for (int d = 0; d < size[s]; d++){
					if (!ingrid(i + dx[d], j + dy[d])) continue;
					grid[i + dx[d]][j + dy[d]]++;
				}
			}
		}
	}
	
	done.insert(grid);
	return vector<T>(0);
}

signed main()
{
	int n;
	VVi grid(10, Vi(10));
	scanf("%d", &n);
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			scanf("%d", &grid[i][j]);
		}
	}
	
	vector<T> res = search(n, grid);
	for (int i = 1; i <= n; i++){
		int x = get<0>(res[i]);
		int y = get<1>(res[i]);
		int s = get<2>(res[i]);
		printf("%d %d %d\n", y, x, ++s);
	}
	
	return 0;
}