#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>
#include <complex>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }

ll sti(string s) {
	ll len = s.length();
	if (len < 1) return 0;
	return (s[len - 1] - '0') + 10 * (sti(s.substr(0, len - 1)));
}

/***
split by t
***/
vcs splitAll(string s, string t) {
	vcs r;
	for (int p = 0; (p = s.find(t)) != s.npos;) {
		r.pb(s.substr(0, p));
		s = s.substr(p + t.size());
	}
	r.pb(s);
	return r;
}



struct Put {
	int x, y, t;
	Put(int x_=0, int y_=0, int t_=0) : x(x_), y(y_), t(t_) {}
};

bool can_put(int x, int y, vector< vci >& board, int type) {
	if (board[y][x]==0) return false;
	if (y+1<10 && board[y+1][x]==0) return false;
	if (y-1>=0 && board[y-1][x]==0) return false;
	if (x+1<10 && board[y][x+1]==0) return false;
	if (x-1>=0 && board[y][x-1]==0) return false;
	if (type==1) return true;
	
	if (y+1<10 && x+1<10 && board[y+1][x+1]==0) return false;
	if (y+1<10 && x-1>=0 && board[y+1][x-1]==0) return false;
	if (y-1>=0 && x+1<10 && board[y-1][x+1]==0) return false;
	if (y-1>=0 && x-1>=0 && board[y-1][x-1]==0) return false;
	if (type==2) return true;
	
	if (y+2<10 && board[y+2][x]==0) return false;
	if (y-2>=0 && board[y-2][x]==0) return false;
	if (x+2<10 && board[y][x+2]==0) return false;
	if (x-2>=0 && board[y][x-2]==0) return false;
	return true;
}

void put(int x, int y, vector< vci >& board, int type, int s) {
	board[y][x] -= s;
	board[y+1][x] -= s;
	board[y-1][x] -= s;
	board[y][x+1] -= s;
	board[y][x-1] -= s;
	if (type==1) return;
	
	board[y+1][x+1] -= s;
	board[y+1][x-1] -= s;
	board[y-1][x+1] -= s;
	board[y-1][x-1] -= s;
	if (type==2) return;
	
	board[y+2][x] -= s;
	board[y-2][x] -= s;
	board[y][x+2] -= s;
	board[y][x-2] -= s;
}

bool isend(vector< vci >& board) {
	for_(i, 0, 10) for_(j, 0, 10) if (board[i][j]>0) return false;
	return true;
}

bool solve(vector< vci >& board, int step, vector<Put>& puts) {
	if (step == 0) {
		if (isend(board)) return true;
		return false;
	}

	for_(i, 1, 9) for_(j, 1, 9) {
		if (board[j][i]==0) continue;
		for_(k, 1, 4) {
			if (can_put(j, i, board, k)) {
				put(j, i, board, k, 1);
				puts.pb(Put(j, i, k));
				if (solve(board, step-1, puts)) return true;
				puts.pop_back();
				put(j, i, board, k, -1);
			}
		}
	}
	
	return false;
}

int main() {
	int n;
	
	string in;
	getline(cin, in); n = sti(in);
	vector< vci > board(10, vci(10, 0));
	
	for_(i, 0, 10) {
		getline(cin, in);
		vcs line = splitAll(in, " ");
		
		for_(j, 0, 10) {
			board[i][j] = sti(line[j]);
		}
	}
	
	vector<Put> ans;
	solve(board, n, ans);
	for_(i, 0, n) {
		cout << ans[i].x << " " << ans[i].y << " " << ans[i].t << endl;
	}
	
	return 0;
}