#include <cstdio>
#include <cstring>
#include <cassert>

using namespace std;

int ax[13], ay[13], as[13];
int mp[12][12];
int size[3] = {3, 3, 5};
int blur[3][5][5] = {{{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}},
 	   				 {{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}},
	      			 {{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 finished;
bool isok[12][12];
void check(int);

bool check2()
{
	memset(isok, 0, sizeof(isok));
	for (int x = 2; x >= 0; x--){
		for (int i = 0; i <= 10 - size[x]; i++){
			for (int j = 0; j <= 10 - size[x]; j++){
				//if (isok[i][j]) continue;
				for (int dy = 0; dy < size[x]; dy++){
					for (int dx = 0; dx < size[x]; dx++){
						if (mp[i + dy][j + dx] < blur[x][dy][dx]) goto na;
					}
				}
				
				for (int dy = 0; dy < size[x]; dy++){
					for (int dx = 0; dx < size[x]; dx++){
						isok[i + dy][j + dx] = 1;
					}
				}
				
				na:;
			}
		}
	}
	
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			if (mp[i][j] != 0 && !isok[i][j]) return (false);
	
	return (true);
}

void decr(int n, int x)
{
	if (finished) return;
	for (int i = 0; i <= 10 - size[x]; i++){
		for (int j = 0; j <= 10 - size[x]; j++){
			for (int dy = 0; dy < size[x]; dy++){
				for (int dx = 0; dx < size[x]; dx++){
					if (mp[i + dy][j + dx] < blur[x][dy][dx]) goto next;
				}
			}
			//if (ok){
				for (int dy = 0; dy < size[x]; dy++){
					for (int dx = 0; dx < size[x]; dx++){
						mp[i + dy][j + dx] -= blur[x][dy][dx];
					}
				}
				
				if (check2()){
					ax[n - 1] = j + (size[x] >> 1); ay[n - 1] = i + (size[x] >> 1); as[n - 1] = x + 1;
					check(n - 1);
					ax[n - 1] = -1;
					if (finished) return;
				}
				
				for (int dy = 0; dy < size[x]; dy++){
					for (int dx = 0; dx < size[x]; dx++){
						mp[i + dy][j + dx] += blur[x][dy][dx];
					}
				}
			//}
			next:;
		}
	}
}
 
void check(int n)
{ 
	if (finished) return;
	if (n == 0){
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				if (mp[i][j] != 0) return;
				
		for (int i = 0; ~ax[i]; i++){
			printf("%d %d %d\n", ax[i], ay[i], as[i]);
	 	}
		finished = true;
		return;
	}
	
	for (int i = 2; i >= 0; i--){
		decr(n, i);
		if (finished) return;
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			scanf("%d", &mp[i][j]);
		}
	}
	
	memset(ax, -1, sizeof(ax));
	check(n);
	return (0);
}