#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 operator < (state b) const {
		rep(i,10)rep(j,10)
			if(a[i][j]!=b.a[i][j])
				return a[i][j]<b.a[i][j];
		return false;
	}
};

set<pair<state,int>> ss;


int dp[310];

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

	int res=0;
	rep(i,10)rep(j,10) if(board.a[i][j]>a[i][j]) return false;
	rep(i,10)rep(j,10) res+=a[i][j]-board.a[i][j];

	if(dp[res]==0) 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}
	};
	if(res>=13&&dp[res-13]){
		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}
	};
	if(res>=9&&dp[res-9]){
		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}
	};
	if(res>=5&&dp[res-5]){
		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;
			}
		}
	}
	ss.insert(make_pair(board,d));
	return false;
}


int main(void){
	dp[0]=1;
	rep(i,200) if(dp[i]) dp[i+13]=dp[i];
	rep(i,200) if(dp[i]) dp[i+9]=dp[i];
	rep(i,200) if(dp[i]) dp[i+5]=dp[i];

	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;
}