#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
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};
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(int base_row,int base_col,Data data){

	if(Found == true)return;

	bool FLG;

	if(data.count == N){

		FLG = true;

		for(int row = 0; row < 10; row++){
			for(int col = 0; col < 10; col++){
				if(data.table[row][col] != ans[row][col]){
					FLG = false;
					break;
				}
			}
			if(!FLG)break;
		}

		if(FLG){

			for(int i = 0; i < N; i++){
				result[i].set(data.info[i].x,data.info[i].y,data.info[i].size);
			}
			Found = true;
		}
		return;
	}

	for(int row = 0; row <= base_row-3; row++){
		for(int col = 0; col < 10; col++){
			if(data.table[row][col] != ans[row][col])return;
		}
	}

	if(base_row >= 2){
		for(int col = 0; col < base_col; col++){
			if(data.table[base_row-2][col] != ans[base_row-2][col])return;
		}
	}


	bool size_1 = true,size_2 = true,size_3 = true;

	//size_1
	for(int i = 0; i < 5; i++){
		if(data.table[base_row+diff_row_1[i]][base_col+diff_col_1[i]] >= ans[base_row+diff_row_1[i]][base_col+diff_col_1[i]]){
			size_1 = false;
			break;
		}
	}

	//size_2
	for(int i = 0; i < 9; i++){
		if(data.table[base_row+diff_row_2[i]][base_col+diff_col_2[i]] >= ans[base_row+diff_row_2[i]][base_col+diff_col_2[i]]){
			size_2 = false;
			break;
		}
	}

	//size_3
	for(int i = 0; i < 13; i++){
		if(data.table[base_row+diff_row_3[i]][base_col+diff_col_3[i]] >= ans[base_row+diff_row_3[i]][base_col+diff_col_3[i]]){
			size_3 = false;
			break;
		}
	}

	if(base_col == 9){

		if(base_row == 9)return;
		recursive(base_row+1,0,data);
	}else{
		recursive(base_row,base_col+1,data);
	}

	if(size_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[base_row+diff_row_1[i]][base_col+diff_col_1[i]]++;
		}

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

		recursive(base_row,base_col,next);
	}

	if(size_2){

		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[base_row+diff_row_2[i]][base_col+diff_col_2[i]]++;
		}

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

		recursive(base_row,base_col,next);
	}

	if(size_3){
		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[base_row+diff_row_3[i]][base_col+diff_col_3[i]]++;
		}

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

		recursive(base_row,base_col,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(1,1,first);

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

	return 0;
}



Measured memory_bytes: 3320