#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
//#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define all(x) x.begin(),x.end()
using namespace std;
int mp[15][15], sum, n;
bool b1(int x, int y) {
	if (mp[x][y] < 1)return 0;
	if (mp[x - 1][y] < 1)return 0;
	if (mp[x + 1][y] < 1)return 0;
	if (mp[x][y - 1] < 1)return 0;
	if (mp[x][y + 1] < 1)return 0;
	return 1;
}
bool b2(int x, int y) {
	if (!b1(x, y))return 0;
	if (mp[x - 1][y - 1] < 1)return 0;
	if (mp[x - 1][y + 1] < 1)return 0;
	if (mp[x + 1][y - 1] < 1)return 0;
	if (mp[x + 1][y + 1] < 1)return 0;
	return 1;
}
bool b3(int x, int y) {
	if (!b2(x, y))return 0;
	if (x < 2 || x > 7 || y < 2 || y > 7)return 0;
	if (mp[x - 2][y] < 1)return 0;
	if (mp[x + 2][y] < 1)return 0;
	if (mp[x][y - 2] < 1)return 0;
	if (mp[x][y + 2] < 1)return 0;
}
void f1(int x, int y) {
	mp[x][y]--;
	mp[x - 1][y]--;
	mp[x + 1][y]--;
	mp[x][y - 1]--;
	mp[x][y + 1]--;
	sum -= 5;
}
void f1_(int x, int y) {
	mp[x][y]++;
	mp[x - 1][y]++;
	mp[x + 1][y]++;
	mp[x][y - 1]++;
	mp[x][y + 1]++;
	sum += 5;
}
void f2(int x, int y) {
	f1(x, y);
	mp[x - 1][y - 1]--;
	mp[x - 1][y + 1]--;
	mp[x + 1][y - 1]--;
	mp[x + 1][y + 1]--;
	sum -= 4;
}
void f2_(int x, int y) {
	f1_(x, y);
	mp[x - 1][y - 1]++;
	mp[x - 1][y + 1]++;
	mp[x + 1][y - 1]++;
	mp[x + 1][y + 1]++;
	sum += 4;
}
void f3(int x, int y) {
	f2(x, y);
	mp[x - 2][y]--;
	mp[x + 2][y]--;
	mp[x][y - 2]--;
	mp[x][y + 2]--;
	sum -= 4;
}
void f3_(int x, int y) {
	f2_(x, y);
	mp[x - 2][y]++;
	mp[x + 2][y]++;
	mp[x][y - 2]++;
	mp[x][y + 2]++;
	sum += 4;
}
bool f(int i, int j) {
	if (n == 0 && sum > 0)return 0;
	if (n > 0 && sum == 0)return 0;
	if (n == 0 && sum == 0)return 1;
	//cout << i << ' ' << j << ' ' << sum << endl;
	if (i >= 9)return 0;
	int in = i, jn = j + 1;
	if (jn == 9) { in++; jn = 1; }
	if (b3(i, j)) {
		f3(i, j); n--;
		if ((sum == 0 && n == 0) || f(i, j)) {
			cout << j << ' ' << i << ' ' << 3 << endl;
			return 1;
		}
		f3_(i, j); n++;
	}
	if (b2(i, j)) {
		f2(i, j); n--;
		if ((sum == 0 && n == 0) || f(i, j)) {
			cout << j << ' ' << i << ' ' << 2 << endl;
			return 1;
		}
		f2_(i, j); n++;
	}
	if (b1(i, j)) {
		if (b3(i, j + 1)) {
			f3(i, j + 1); n--;
			if ((sum == 0 && n == 0) || f(i, j)) {
				cout << j + 1 << ' ' << i << ' ' << 3 << endl;
				return 1;
			}
			f3_(i, j + 1); n++;
		}
		if (b3(i + 1, j)) {
			f3(i + 1, j); n--;
			if ((sum == 0 && n == 0) || f(i, j)) {
				cout << j << ' ' << i + 1 << ' ' << 3 << endl;
				return 1;
			}
			f3_(i + 1, j); n++;
		}
		f1(i, j); n--;
		if ((sum == 0 && n == 0) || f(i, j)) {
			cout << j << ' ' << i << ' ' << 1 << endl;
			return 1;
		}
		f1_(i, j); n++;
	}
	if (f(in, jn))return 1;
	return 0;
}
signed main() {
	cin >> n;
	for0(i, 10)for0(j, 10) { cin >> mp[i][j]; sum += mp[i][j]; }
	f(1, 1);
}
