#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int n = 10;
int m, a[n][n];
const int sz[] = {5, 9, 13};
const int dy[][13] = {
	{-1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
	{-1, -1, -1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
	{-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2}
};
const int dx[][13] = {
	{0, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{-1, 0, 1, -1, 0, 1, -1, 0, 1, 0, 0, 0, 0},
	{0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}
};

vector<pi> v;

inline bool can(int y, int x, int t, int nul = 0){
	if(nul) rep(d, sz[t]){
		int ny = y + dy[t][d], nx = x + dx[t][d];
		if(ny < 0 || nx < 0 || ny >= n || nx >= n) continue;
		a[ny][nx] += nul;
	}
	else rep(d, sz[t]){
		int ny = y + dy[t][d], nx = x + dx[t][d];
		if(ny < 0 || nx < 0 || ny >= n || nx >= n) continue;
		if(!a[ny][nx]) return 0;
	}
	return 1;
}
inline void fill(bool ok[n][n], int y, int x, int t){
	rep(d, sz[t]){
		int ny = y + dy[t][d], nx = x + dx[t][d];
		if(ny < 0 || nx < 0 || ny >= n || nx >= n) continue;
		ok[ny][nx] = 1;
	}
}

inline void rec(int m, int y, int x){
	if(m == 0){
		rep(i, n) rep(j, n) if(a[i][j]) return;
		rep(i, v.size()) cout << v[i].first / 10 << " " << v[i].first % 10 << " " << v[i].second << endl;
		exit(0);
	}
	bool ok[n][n] = {};
	vector<pi> cand;
	
	rep(i, n) rep(j, n) if(i > y || i == y && j >= x)
	if(a[i][j]) for(int t = 2; i >= 0; t--){
		if(can(i, j, t)){
			fill(ok, i, j, t);
			cand.pb(mp(t, i * 10 + j));
			break;
		}
	}
	rep(i, n) rep(j, n) if(a[i][j] && !ok[i][j]) return;
	
	rep(ii, cand.size()){
		int i = cand[ii].second / 10, j = cand[ii].second % 10;
		int t = cand[ii].first;
		
		for(; t >= 0; t--){
			//if(i >= 3 && t < cand[ii].first) break;
			can(i, j, t, -1);
			v.pb(mp(j * 10 + i, t + 1));
			rec(m - 1, i, j);
			v.pop_back();
			can(i, j, t, 1);
		}
	}
}

int main(){
	cin >> m;
	rep(i, n) rep(j, n) cin >> a[i][j];
	rec(m, 0, 0);
	return 0;
}