#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<n;i++)
#define repc(i,n) for(int i=0;i<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){
	
	int a = 5;
	int c = 2;
	int d = 0;
	
	if(p.kind!=2){
		a=3;
		c=1;
		d=1;
	}
	
	bool flg = true;
	repc(dy,a){
		repc(dx,a){
			int nx = p.x+dx-c;
			int ny = p.y+dy-c;
			
			if(nx<0 || ny<0 || nx>=N || ny>=N)continue;
			
			if(color[p.kind][dy+d][dx+d]==1 && b.board[ny][nx]==0)flg=false;
		}
	}
	
	return flg;
}

void put(B& b, P p,int rev=1){
	
	int a = 5;
	int c = 2;
	int d = 0;
	
	if(p.kind!=2){
		a=3;
		d=1;
		c=1;
	}
	repc(dy,a){
		repc(dx,a){
			int nx = p.x+dx-c;
			int ny = p.y+dy-c;
			
			if(nx<0 || ny<0 || nx>=N || ny>=N)continue;
			
			if(color[p.kind][dy+d][dx+d]==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;
}

bool boardvalid2(B& b){
	B c;
	rep(kind,3){
		rep(y,N){
			rep(x,N){
				P np = P(x,y,kind);
				if(canput(b, np)){
					put(c, np);
				}
			}
		}
	}
	
	rep(i,N){
		rep(j,N){
			if(b.board[i][j]>0 && c.board[i][j]==0)return false;
		}
	}
	return true;
}
bool boardvalid(B& b){
	rep(i,N){
		rep(j,N){
			if(b.board[i][j]<0)return false;
		}
	}
	
	return boardvalid2(b);
}

vector<P> answ;
int n;

bool saiki(B& b, int x, int y, vector<P>& hoge){
	
	if(hoge.size()>n){
		return false;
	}
	
	if(x==N-1 && y==N-1){
		if(!boardvalid(b) || hoge.size()!=n)return false;
		
		answ = hoge;
		return true;
	}
	
	int nx = (x+1)%N;
	int ny = y+(x+1)/N;
	
	if(b.board[y][x]==0){
		
		return saiki(b, nx, ny, hoge);
	}
	
	bool ret = false;
	int dkind[]={2,1,0};
	rep(ppp, 3){
		int kind = dkind[ppp];
		rep(dy,5){
			rep(dx,5){
				if(color[kind][dy][dx]==1){
					P np = P(x+dx-2, y+dy-2, kind);
					if(canput(b, np)){
						put(b, np);
						hoge.pb(np);
						
						if(boardvalid(b)){
							ret |= saiki(b, x,y, hoge);
						}
						put(b, np, -1);
						hoge.pop_back();
					}
				}
				if(ret)return true;
			}
		}
	}
	
	return false;
}

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