#include <iostream>
#include <cstdio>

#define reep(i,n,m) for(int i=(n);i<(m);i++)
#define rep(i,n) reep(i,0,n)

using namespace std;

class Liquid{
public:
	int x,y,size;
};

int fld[10][10];
int N;
Liquid ans[12];
int lest = 0;

void draw(int x, int y, int add){
	if(x<0||x>=10||y<0||y>=10){
		return;
	}
	fld[y][x] += add;
	lest += add;
}

bool hang(int x, int y, int add, int size){
	int sdx[] = {0,0,1,-1};
	int sdy[] = {1,-1,0,0};

	int mdx[] = {1,1,-1,-1};
	int mdy[] = {1,-1,1,-1};
	fld[y][x] += add;
	lest += add;
	rep(i,4){
		int nx = x+sdx[i];
		int ny = y+sdy[i];
		draw(nx,ny,add);

		if(size>=2){
			nx = x+mdx[i];
			ny = y+mdy[i];
			draw(nx,ny,add);
		}

		if(size>=3){
			nx = x+sdx[i]*2;
			ny = y+sdy[i]*2;
			draw(nx,ny,add);
		}
	}

	for(int dy=-2;dy<=2;dy++){
		for(int dx=-2;dx<=2;dx++){
			int nx = x+dx;
			int ny = y+dy;
			if(nx<0||nx>=10||ny<0||ny>=10){
				continue;
			}
			if(fld[ny][nx]<0){
				return false;
			}
		}
	}
	return true;
}

/*
bool isWhite(){
	bool ret = true;
	rep(y,10){
		rep(x,10){
			if(fld[y][x]){
				ret = false;
			}
		}
	}
	return ret;
}*/

bool flg=false;

void dfs(int x, int y, int n){
	if(flg){
		return;
	}
	if(n==N){
		/*puts("{");
		rep(i,N){
			printf("%d %d %d\n",ans[i].x, ans[i].y, ans[i].size);
		}
		puts("}");*/
		if(lest!=0){
			return;
		}
		rep(i,N){
			printf("%d %d %d\n",ans[i].x, ans[i].y, ans[i].size);
		}
		flg=true;
		return;
	}
	reep(i,1,4){
		if(!hang(x,y,-1,i)){
			hang(x,y,1,i);
			break;
		}
		ans[n].x = x;
		ans[n].y = y;
		ans[n].size = i;
		dfs(x,y,n+1);
		hang(x,y,1,i);
	}
	int nx = x + 1;
	int ny = y;
	if(nx==10){
		nx=0;
		ny++;
	}
	if(ny==10){
		return;
	}
	dfs(nx,ny,n);
}

int main(){
	cin >> N;
	rep(y,10){
		rep(x,10){
			cin >> fld[y][x];
			lest += fld[y][x];
		}
	}


	dfs(0,0,0);
	return 0;
}