
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;

int pattern_small[] = {
	0,1,0, 
	1,1,1,
	0,1,0
};

int pattern_med[] = {
	1,1,1,
	1,1,1,
	1,1,1
};

int pattern_big[] = {
	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
};

int mat[12][12];
int used[12][12];

bool valid(int y, int x, int off_y, int off_x, int h, int w, int *pattern){
	int sy = y - off_y;
	int sx = x - off_x;
	if(sy < 0 || sx < 0)return false;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++){
		int ny = sy + i;
		int nx = sx + j;
		if(pattern[i*w+j] && (mat[ny][nx] <= 0)){
			return false;
		}
	}
	return true;
}

void update(int y, int x, int off_y, int off_x, int h, int w, int *pattern, int sign){
	int sy = y - off_y;
	int sx = x - off_x;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++){
		int ny = sy + i;
		int nx = sx + j;
		mat[ny][nx] += sign * pattern[i*w+j];
	}
}

bool lastCheck(){
	for(int y=0;y<10;y++)for(int x=0;x<10;x++){
		if(mat[y][x] != 0)return false;
	}
	return true;
}

bool dfs(int k, int n){
	if(k == 0)return lastCheck();
	if(n >= 10 * 10)return false;

	int y = n / 10;
	int x = n % 10;

	if(valid(y, x, 1, 1, 3, 3, pattern_small)){
		used[y][x] = 1;
		update(y, x, 1, 1, 3, 3, pattern_small, -1);

		if(dfs(k-1, n+1)){
			return true;
		}

		update(y, x, 1, 1, 3, 3, pattern_small, +1);
		used[y][x] = 0;
	}

	
	if(valid(y, x, 1, 1, 3, 3, pattern_med)){
		used[y][x] = 2;
		update(y, x, 1, 1, 3, 3, pattern_med, -1);

		if(dfs(k-1, n+1)){
			return true;
		}

		update(y, x, 1, 1, 3, 3, pattern_med, +1);
		used[y][x] = 0;
	}

	
	if(valid(y, x, 2, 2, 5, 5, pattern_big)){
		used[y][x] = 3;
		update(y, x, 2, 2, 5, 5, pattern_big, -1);

		if(dfs(k-1, n+1)){
			return true;
		}

		update(y, x, 2, 2, 5, 5, pattern_big, +1);
		used[y][x] = 0;
	}

	return dfs(k, n+1);
}

int main()
{
	
	int K;
	cin >> K;

	for(int y=0;y<10;y++)for(int x=0;x<10;x++)cin >> mat[y][x];
	dfs(K, 0);

	for(int y=0;y<10;y++)for(int x=0;x<10;x++){
		if(used[y][x] != 0){
			cout << x << " " << y << " " << used[y][x] << endl;
		}
	}
	return 0;
}