#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
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 dy[3][4] = {
	-1,0,1,0,
	-1,-1,1,1,
	-2,0,2,0
};
const int dx[3][4] = {
	0,1,0,-1,
	-1,1,1,-1,
	0,2,0,-2
};

int N;
bool found;

bool can(int fld[10][10],int y,int x,int size){
	for(int k=0;k<4;k++){
		int ny = y+dy[size][k],
			nx = x+dx[size][k];
		if(ny<0 || 10<=ny || nx<0 || 10<=nx || fld[ny][nx]==0) return false;
	}
	return true;
}

void dye(int fld[10][10],int y,int x,int size,int v){
	for(int k=0;k<4;k++){
		int ny = y+dy[size][k],
			nx = x+dx[size][k];
		fld[ny][nx] += v;
	}
}

void dfs(int fld[10][10],vector<Ink> &ink,int y,int x){
	if(found) return;
	bool white = true;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			if(fld[i][j]>N-ink.size()) return;
			if(fld[i][j]!=0){
				white = false;
			}
		}
	}
	if(white && 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+1);
			found = true;
		}
		return;
	}

	for(int i=y;i<10;i++){
		for(int j=(i==y)?x:0;j<10;j++){
			if(fld[i][j]==0) continue;
			fld[i][j]--;
			int size;
			for(size=0;size<3;size++){
				if(can(fld,i,j,size)==false) break;
				dye(fld,i,j,size,-1);
				ink.push_back(Ink(i,j,size));
				dfs(fld,ink,i,j);
				ink.pop_back();
			}
			while(size--){
				dye(fld,i,j,size,1);
			}
			fld[i][j]++;
		}
	}
}

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,0,0);
	return 0;
}