#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N,ans[10][10];
int diff_row_1[5] = {-1,0,0,0,1},diff_col_1[5] = {0,-1,0,1,0};
int diff_row_2[9] = {-1,-1,-1,0,0,0,1,1,1},diff_col_2[9] = {-1,0,1,-1,0,1,-1,0,1};
int diff_row_3[13] = {-2,-1,-1,-1,0,0,0,0,0,1,1,1,2},diff_col_3[13] = {0,-1,0,1,-2,-1,0,1,2,-1,0,1,0};

struct Info{
	void set(int arg_x,int arg_y,int arg_size){
		x = arg_x;
		y = arg_y;
		size = arg_size;
	}
	int x,y,size;
};

struct Data{
	int table[10][10];
	Info info[13];
	int count;
};

map<string,bool> MAP;

int main(){

	Info result[13];
	int FLG;

	scanf("%d",&N);

	Data first;
	first.count = 0;

	for(int i = 0; i < 10; i++){
		for(int k = 0; k < 10; k++){
			scanf("%d",&ans[i][k]);
			first.table[i][k] = 0;
		}
	}

	queue<Data> Q;
	Q.push(first);

	Data data;

	while(!Q.empty()){

		data = Q.front();
		Q.pop();

		if(data.count == N){ //N???????????????????????????????????¢????????????????????????N-1?????\?????§????????¢??§????????´????????????????????\????????????????????????????????¨?§£?????????

			FLG = 1;

			//????????¢??????
			for(int y = 0; y < 10; y++){
				for(int x = 0; x < 10; x++){
					if(data.table[y][x] != ans[y][x]){
						FLG = 0;
						break;
					}
				}
				if(FLG == 0)break;
			}

			if(FLG == 1){ //????????¢

				//?????°?????¢?¨?
				for(int i = 1; i <= N; i++){
					result[i].set(data.info[i].x,data.info[i].y,data.info[i].size);
				}
				break;
			}else{
				continue;
			}
		}

		//?????????1????????????
		for(int y = 1; y <= 8; y++){
			for(int x = 1; x <= 8; x++){
				//y,x???????????¨????????????????????¨?????£?§£???????????????1??\??????????????¨????¢??????????
				FLG = 1;
				for(int i = 0; i < 5; i++){
					if(data.table[y+diff_row_1[i]][x+diff_col_1[i]] >= ans[y+diff_row_1[i]][x+diff_col_1[i]]){
						FLG = 0;
						break;
					}
				}

				if(FLG == 1){ //??????????????´???
					Data next;
					for(int i = 0; i < 10; i++){
						for(int k = 0; k < 10; k++)next.table[i][k] = data.table[i][k];
					}
					//?????????
					for(int i = 0; i < 5; i++){
						next.table[y+diff_row_1[i]][x+diff_col_1[i]]++;
					}

					//??¢????????£?????????????¢??????????
					string tmp;
					for(int row = 0; row < 10; row++){
						for(int col = 0; col < 10; col++){
							tmp.append(to_string(next.table[row][col]));
						}
					}

					auto at = MAP.find(tmp);

					if(at != MAP.end())continue; //??¢????????£????????????continue;
					MAP[tmp] = true;

					for(int i = 1; i <= data.count;i++){
						next.info[i].set(data.info[i].x,data.info[i].y,data.info[i].size);
					}
					next.count = data.count+1;
					next.info[next.count].set(x,y,1);
					Q.push(next);
				}
			}
		}

		//?????????2????????????
		for(int y = 1; y <= 8; y++){
			for(int x = 1; x <= 8; x++){
				//y,x???????????¨????????????????????¨?????£?§£???????????????1??\??????????????¨????¢??????????
				FLG = 1;
				for(int i = 0; i < 9; i++){
					if(data.table[y+diff_row_2[i]][x+diff_col_2[i]] >= ans[y+diff_row_2[i]][x+diff_col_2[i]]){
						FLG = 0;
						break;
					}
				}

				if(FLG == 1){ //??????????????´???
					Data next;
					for(int i = 0; i < 10; i++){
						for(int k = 0; k < 10; k++)next.table[i][k] = data.table[i][k];
					}
					//?????????
					for(int i = 0; i < 9; i++){
						next.table[y+diff_row_2[i]][x+diff_col_2[i]]++;
					}

					//??¢????????£?????????????¢??????????
					string tmp;
					for(int row = 0; row < 10; row++){
						for(int col = 0; col < 10; col++){
							tmp.append(to_string(next.table[row][col]));
						}
					}

					auto at = MAP.find(tmp);

					if(at != MAP.end())continue; //??¢????????£????????????continue;
					MAP[tmp] = true;


					for(int i = 1; i <= data.count;i++){
						next.info[i].set(data.info[i].x,data.info[i].y,data.info[i].size);
					}
					next.count = data.count+1;
					next.info[next.count].set(x,y,2);
					Q.push(next);
				}
			}
		}

		//?????????3????????????
		for(int y = 2; y <= 7; y++){
			for(int x = 2; x <= 7; x++){
				//y,x???????????¨????????????????????¨?????£?§£???????????????1??\??????????????¨????¢??????????
				FLG = 1;
				for(int i = 0; i < 13; i++){
					if(data.table[y+diff_row_3[i]][x+diff_col_3[i]] >= ans[y+diff_row_3[i]][x+diff_col_3[i]]){
						FLG = 0;
						break;
					}
				}

				if(FLG == 1){ //??????????????´???
					Data next;
					for(int i = 0; i < 10; i++){
						for(int k = 0; k < 10; k++)next.table[i][k] = data.table[i][k];
					}
					//?????????
					for(int i = 0; i < 13; i++){
						next.table[y+diff_row_3[i]][x+diff_col_3[i]]++;
					}

					//??¢????????£?????????????¢??????????
					string tmp;
					for(int row = 0; row < 10; row++){
						for(int col = 0; col < 10; col++){
							tmp.append(to_string(next.table[row][col]));
						}
					}

					auto at = MAP.find(tmp);

					if(at != MAP.end())continue; //??¢????????£????????????continue;
					MAP[tmp] = true;


					for(int i = 1; i <= data.count;i++){
						next.info[i].set(data.info[i].x,data.info[i].y,data.info[i].size);
					}
					next.count = data.count+1;
					next.info[next.count].set(x,y,3);
					Q.push(next);
				}
			}
		}
	}

	for(int i = 1; i <= N; i++){
		printf("%d %d %d\n",result[i].x,result[i].y,result[i].size);
	}

	return 0;
}