#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>
  
using namespace std;
  
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

#define pb push_back

#define X real()
#define Y imag()

const int N = 10;

class P{
	public:
	int x,y,kind;
	P(int x,int y,int kind):x(x),y(y),kind(kind){}
};


class B{
	public:
	int board[N][N];
	B(){rep(i,N)rep(j,N)board[i][j]=0;}
	
	B copy(){
		B b;
		rep(i,N)rep(j,N)b.board[i][j]=board[i][j];
		return b;
	}
};

int color[3][5][5]={
	{
		{0,0,0,0,0},
		{0,0,1,0,0},
		{0,1,1,1,0},
		{0,0,1,0,0},
		{0,0,0,0,0},
	},
	{
		{0,0,0,0,0},
		{0,1,1,1,0},
		{0,1,1,1,0},
		{0,1,1,1,0},
		{0,0,0,0,0},
	},
	{
		{0,0,1,0,0},
		{0,1,1,1,0},
		{1,1,1,1,1},
		{0,1,1,1,0},
		{0,0,1,0,0},
	}
};

bool canput(B& b, P p){
	
	bool flg = true;
	rep(dy,5){
		rep(dx,5){
			int nx = p.x+dx-2;
			int ny = p.y+dy-2;
			
			if(nx<0 || ny<0 || nx>=N || ny>=N)continue;
			
			if(color[p.kind][dy][dx]==1 && b.board[ny][nx]==0)flg=false;
		}
	}
	
	return flg;
}

void put(B& b, P p,int rev=1){
	rep(dy,5){
		rep(dx,5){
			int nx = p.x+dx-2;
			int ny = p.y+dy-2;
			
			if(nx<0 || ny<0 || nx>=N || ny>=N)continue;
			
			if(color[p.kind][dy][dx]==1){
				b.board[ny][nx]-=rev;
			}
		}
	}
}

vector<P> getcand(B& b){
	vector<P> ret;
	rep(y,N){
		rep(x,N){
			rep(k,3){
				if(canput(b, P(x,y,k))){
					ret.pb(P(x,y,k));
				}
			}
		}
	}
	return ret;
}

vector<P> answ;

bool saiki(B& b, vector<P>& cand, int depth, vector<P>& hoge){
	
	
	if(depth==cand.size()){
		bool ok = true;
		rep(i,N){
			rep(j,N){
				if(b.board[i][j]!=0)ok=false;
			}
		}
		
		if(ok){
			answ = hoge;
		}
		/*
		rep(i,hoge.size()){
			printf("%d %d %d\n",hoge[i].x,hoge[i].y,hoge[i].kind+1);
		}
		rep(i,N){
			rep(j,N)printf("%d ",b.board[i][j]);puts("");
		}puts("");
		*/
		return ok;
	}
	
	
	bool next1 = saiki(b, cand, depth+1, hoge);
	if(next1)return true;
	
	bool next2;
	
	put(b, cand[depth]);
	{
		//vector<P> cand2 = getcand(b);
		bool ok = true;
		
		
		rep(i,N)rep(j,N)if(b.board[i][j]<0)ok=false;
		/*
		rep(i,cand2.size())put(b, cand2[i]);
		{
			rep(i,N){
				rep(j,N){
					if(b.board[i][j]>0)ok=false;
				}
			}
		}
		rep(i,cand2.size())put(b, cand2[i], -1);
		*/
		if(!ok){
			put(b,cand[depth], -1);
			return false;
		}
		
		hoge.push_back(cand[depth]);
		next2 = saiki(b, cand, depth+1, hoge);
		hoge.pop_back();
	}
	put(b, cand[depth], -1);
	
	return next2;
}

int main(){
	int n;
	B b;
	
	cin>>n;
	rep(i,N)rep(j,N)cin>>b.board[i][j];
	
	vector<P> cand = getcand(b);
	
	/*
	rep(i,cand.size()){
		printf("*%d %d %d\n",cand[i].x,cand[i].y,cand[i].kind);
	}*/
	
	vector<P> aaa;
	
	saiki(b, cand, 0, aaa);
	
	rep(i,answ.size()){
		printf("%d %d %d\n",answ[i].x,answ[i].y,answ[i].kind+1);
	}
	/*
	
	rep(i,N){
		rep(j,N)printf("%d ",b.board[i][j]);puts("");
	}*/
}