#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
using namespace std;

struct Ink{
	int y,x,size;
	Ink(){}
	Ink(int _y,int _x,int _size){
		y=_y; x=_x; size=_size;
	}
};

const int blur_x[3][4] = {{0,1,0,-1},{1,1,-1,-1},{0,2,0,-2}},
		  blur_y[3][4] = {{-1,0,1,0},{-1,1,1,-1},{-2,0,2,0}};
int N;
bool ansflag;

void dfs(int fld[10][10],vector<Ink> ink){
	if(ansflag==true) return;
	bool flag=true;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			//printf("%d ",fld[i][j]);
			int fld_c[10][10];
			for(int k=0;k<10;k++)for(int l=0;l<10;l++) fld_c[k][l] = fld[k][l];
			if(--fld_c[i][j]<0) continue;
			flag = false;
			for(int k=0;k<3;k++){
				for(int l=0;l<4;l++){
					int ny,nx;
					ny = i+blur_y[k][l];
					nx = j+blur_x[k][l];
					if(ny<0 || 10<=ny || nx<0 || 10<=nx || --fld_c[ny][nx]<0) goto NEXT;
				}
				ink.push_back(Ink(i,j,k+1));
				int fld_cc[10][10];
				for(int l=0;l<10;l++)for(int m=0;m<10;m++) fld_cc[l][m] = fld_c[l][m];
				dfs(fld_cc,ink);
				ink.pop_back();
			}
			NEXT:;
		}//puts("");
	}//puts("");
	if(flag==true && ink.size()==N){
		for(int i=0;i<ink.size();i++){
			printf("%d %d %d\n",ink[i].x,ink[i].y,ink[i].size);
		}
		ansflag = true;
		return;
	}
}

int main(){
	int fld[10][10];
	cin>>N;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin>>fld[i][j];
		}
	}
	vector<Ink> ink;
	dfs(fld,ink);
	return 0;
}