#include <bits/stdc++.h>
#define range(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) range(i,0,n)
using namespace std;

int n;
int a[10][10];

class state{
	public:
		int a[10][10];
};

bool dfs(int d,state board){
	if(d==n){
		rep(i,10)rep(j,10) if(board.a[i][j]!=a[i][j]) return false;
		return true;
	}
	rep(i,10)rep(j,10) if(board.a[i][j]>a[i][j]) return false;

	int b[5][5]={
		{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}
	};
	rep(i,6)rep(j,6){
		state nboard=board;
		rep(k,5)rep(l,5) nboard.a[i+k][j+l]+=b[k][l];
		if(dfs(d+1,nboard)){
			cout << j+2 << " " << i+2 << " " << 3 << endl;
			return true;
		}
	}

	int m[3][3]={
		{1,1,1},
		{1,1,1},
		{1,1,1}
	};
	rep(i,8)rep(j,8){
		state nboard=board;
		rep(k,3)rep(l,3) nboard.a[i+k][j+l]+=m[k][l];
		if(dfs(d+1,nboard)){
			cout << j+1 << " "  << i+1 << " " << 2 << endl;
			return true;
		}
	}

	int s[3][3]={
		{0,1,0},
		{1,1,1},
		{0,1,0}
	};
	rep(i,8)rep(j,8){
		state nboard=board;
		rep(k,3)rep(l,3) nboard.a[i+k][j+l]+=s[k][l];
		if(dfs(d+1,nboard)){
			cout << j+1 << " "  << i+1 << " " << 1 << endl;
			return true;
		}
	}
	return false;
}


int main(void){
	cin >> n;
	rep(i,10)rep(j,10) cin >> a[i][j];
	state init;
	rep(i,10)rep(j,10) init.a[i][j]=0;
	dfs(0,init);
	return 0;
}