#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <queue>
#include <sstream>
#include <climits>
#include <cmath>
#include <list>
#include <functional>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EPS 1e-12
#define pri_max 60000
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;

int m[15][15] = {};
int blur[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 }
	}

};

void deb()
{
	for (int y = 1; y <= 10; y++)
	{
		for (int x = 1; x <= 10; x++)
		{
			cout<< m[y][x];
		}
		cout << endl;
	}
}

bool check(int y, int x, int k)
{
	for (int Y = 0; Y < 5; Y++)
	{
		for (int X = 0; X < 5; X++)
		{
			if (blur[k][Y][X])
			{
				if (y + Y > 10 || x + X > 10)return false;
				if (m[y + Y][x + X] - 1 < 0)return false;
			}
		}
	}
	return true;
}
void paint(int y, int x, int k, int p)
{
	for (int Y = 0; Y < 5; Y++)
	{
		for (int X = 0; X < 5; X++)
		{
			if (blur[k][Y][X])
			{
				m[y + Y][x + X] += p;
			}
		}
	}
}

bool dfs(int y, int x, int s)
{
	
	if (x == 11)return dfs(y + 1, 0, s);
	if (y == 11)return s == 0;
	if (m[y][x] != 0)return false;
	for (int i = 0; i < 3; i++)
	{
		if (check(y, x, i))
		{
			paint(y, x, i, -1);
			if (dfs(y, x, s - 1))
			{
				cout << x+1 << " " << y+1 << " " << i + 1 << endl;
				return true;
			}
			paint(y, x, i, 1);
		}
	}
	return dfs(y, x + 1, s);
}

int main()
{
	int n;
	cin >> n;
	for (int y = 1; y <= 10; y++)
	{
		for (int x = 1; x <= 10; x++)
		{
			cin >> m[y][x];
		}
	}
	dfs(0, 0, n);

}