#include <cstdio>
#include <cstring>

using namespace std;

int ax[12], ay[12], as[12];
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;
void check(int);

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++){
			bool ok = true;
			for (int dy = 0; dy < size[x]; dy++){
				for (int dx = 0; dx < size[x]; dx++){
					ok &= (mp[i + dy][j + dx] >= blur[x][dy][dx]);
				}
			}
			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];
					}
				}
				
				ax[n - 1] = j + size[x] / 2; ay[n - 1] = i + size[x] / 2; as[n - 1] = x + 1;
				check(n - 1);
				if (finished) return;
				ax[n - 1] = -1;
				
				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];
					}
				}
			}
		}
	}
}
 
void check(int n)
{ 
	if (finished) return;
	if (n == 0){
	 	bool ok = true;
		for (int i = 0; i < 10; i++)
	 		for (int j = 0; j < 10; j++)
				ok &= !mp[i][j];
	 	if (ok){
			for (int i = 0; ~ax[i]; i++)
				printf("%d %d %d\n", ax[i], ay[i], as[i]);
			finished = true;
	 	}
	}
	
	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);
}