#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
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};
bool Found = false;

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;
};

Info result[13];

void recursive(Data data){

	if(data.count > N || Found == true)return;

	int FLG;

	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);
			}
			Found = true;
			return;
		}
	}

	//?????????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]]++;
				}
				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);
				recursive(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]]++;
				}
				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);
				recursive(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]]++;
				}
				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);
				recursive(next);
			}
		}
	}

}


int main(){

	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;
		}
	}

	recursive(first);

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

	return 0;
}