#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef pair<int, int> pii;
typedef pair<int, pii> pip;

int n;
int maps[10][10];
int cnt; // ???????????????????¨?
int m[3] = {5, 9, 13};
stack<pip> ans; // x, y, size

bool ismap(int x, int y) {
	return x >= 0 && x < 10 && y >= 0 && y < 10;
}

// (x, y) ??? ????????? ?????¨???????????§?????§??????
int sim(int x, int y) {
	int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
	int nx, ny;
	int res = 0;
	
	if (!maps[y][x]) return false;
	
	REP(i, 4) {
		nx = x + dx[i];
		ny = y + dy[i];
		if (!ismap(nx, ny) || !maps[ny][nx]) return res;
	}
	res++;
	
	REP(i, 2) REP(j, 2) {
		nx = x + (j == 0 ? -1 : 1);
		ny = y + (i == 0 ? -1 : 1);
		if (!ismap(nx, ny) || !maps[ny][nx]) return res;
	}
	res++;
	
	REP(i, 4) {
		nx = x + dx[i]*2;
		ny = y + dy[i]*2;
		if (!ismap(nx, ny) || !maps[ny][nx]) return res;
	}
	res++;
	
	return res;
}

// (x, y)?????????????????????s????????????k?¶????
void sum(int x, int y, int s, int k) {
	int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
	int nx, ny;
	
	switch(s) {
		case 3:
			REP(i, 4) {
				nx = x + dx[i]*2;
				ny = y + dy[i]*2;
				maps[ny][nx] += k;
			}
		case 2:
			REP(i, 2) REP(j, 2) {
				nx = x + (j == 0 ? -1 : 1);
				ny = y + (i == 0 ? -1 : 1);
				maps[ny][nx] += k;
			}
		case 1:
			REP(i, 4) {
				nx = x + dx[i];
				ny = y + dy[i];
				maps[ny][nx] += k;
			}
	}
}

// (x, y) ????????¢?´¢ ?????? k ???
bool dfs(int x, int y, int k) {
	if (k == 0) return cnt == 0;
	if (k * m[2] < cnt) return false;
	if (ismap(x - 3, y - 3) && maps[y - 3][x - 3]) return false;
	
	int ms = sim(x, y);
	REP(i, ms) {
		sum(x, y, i + 1, -1);
		cnt -= m[i];
		
		if (dfs(x, y, k - 1)) {
			ans.push(pip(x, pii(y, i + 1)));
			return true;
		}
		
		cnt += m[i];
		sum(x, y, i + 1, 1);
	}
	
	int tmp = y * 10 + x + 1;
	if (tmp == 100) return false;
	if (dfs(tmp % 10, tmp / 10, k)) return true;
	
	return false;
}

int main() {
	cin >> n;
	REP(i, 10) REP(j, 10) {
		scanf("%d", &maps[i][j]);
		cnt += maps[i][j];
	}
	
	dfs(0, 0, n);
	
	
	while(!ans.empty()) {
		pip p = ans.top(); ans.pop();
		printf("%d %d %d\n", p.first, p.second.first, p.second.second);
	}
	
	
	return 0;
}