#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

int blur[3][5][5] = {
	{
		{ 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,0,1,1,1 },
		{ 0,0,1,1,1 },
		{ 0,0,1,1,1 },
		{ 0,0,0,0,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 },
	}
};
int A[20][20] = {};

bool check(int b, int i, int j) {
	rep(p, 0, 5)rep(q, 0, 5) if (A[i + p][j + q - 2] - blur[b][p][q] < 0)return false;
	return true;
}

void fblur(int b, int i, int j) {
	rep(p, 0, 5)rep(q, 0, 5) A[i + p][j + q - 2] -= blur[b][p][q];
}

void frblur(int b, int i, int j) {
	rep(p, 0, 5)rep(q, 0, 5) A[i + p][j + q - 2] += blur[b][p][q];
}

bool rec(int n, int i, int j) {
	if (n < 0)return false;
	if (i == 10 && n == 0)return true;
	if (A[i][j] == 0)return rec(n, i + (j == 9), (j + 1) % 10);
	rep(b, 0, 3) {
		if (!check(b, i, j))continue;
		fblur(b, i, j);
		if (rec(n - 1, i, j)) {
			cout << j + (b == 1) << " " << i + 1 + (b == 2) << " " << b + 1 << endl;
			return true;
		}
		frblur(b, i, j);
	}
	return false;
}

signed main() {
	int n; cin >> n;
	rep(i, 0, 10)rep(j, 0, 10)cin >> A[i][j];
	rec(n, 0, 0);
	return 0;
}