#include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n;
int c[10][10];
vector<int> ct, cx, cy;

bool add(int i, int j, int t, int v){
	vector<int> y[3] = {
		{0, -1, 0, 1, 0},
		{0, 1, 2, 0, 1, 2, 0, 1, 2},
		{0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}
	};
	vector<int> x[3] = {
		{0, 1, 1, 1, 2},
		{0, 0, 0, 1, 1, 1, 2, 2, 2},
		{0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4}
	};

	rep(k, x[t].size()){
		int nx = i + x[t][k];
		int ny = j + y[t][k];
		if(nx < 0 || nx >= 10 || ny < 0 || ny >= 10 || c[nx][ny] + v < 0){
			return false;
		}
	}

	rep(k, x[t].size()){
		int nx = i + x[t][k];
		int ny = j + y[t][k];
		c[nx][ny] += v;
	}
	return true;
}

void dfs(int i, int j){
	if(i == 10 && j == 0 && cx.size() == n){
		rep(k, n){
			if(ct[k] == 0){
				printf("%d %d %d\n", cy[k], cx[k] + 1, ct[k] + 1);
			}
			else if(ct[k] == 1){
				printf("%d %d %d\n", cy[k] + 1, cx[k] + 1, ct[k] + 1);
			}
			else{
				printf("%d %d %d\n", cy[k], cx[k] + 2, ct[k] + 1);
			}
		}
	}

	// printf("%d, %d\n", i, j);

	if(c[i][j] == 0){
		if(j == 9){
			dfs(i + 1, 0);
		}
		else{
			dfs(i, j + 1);
		}
	}
	else if(cx.size() < n){
		rep(k, 3){
			if(add(i, j, k, -1)){
				cx.push_back(i);
				cy.push_back(j);
				ct.push_back(k);

				/*rep(a, 10){
					rep(b, 10){
						printf("%d ", c[a][b]);
					}
					printf("\n");
				}
				printf("\n");*/

				dfs(i, j);

				add(i, j, k, 1);
				cx.pop_back();
				cy.pop_back();
				ct.pop_back();

				/*rep(a, 10){
					rep(b, 10){
						printf("%d ", c[a][b]);
					}
					printf("\n");
				}
				printf("\n");*/
			}
		}
	}
}

int main(){
	scanf("%d", &n);
	rep(i, 10){
		rep(j, 10){
			scanf("%d", &c[i][j]);
		}
	}

	/*rep(a, 10){
		rep(b, 10){
			printf("%d ", c[a][b]);
		}
		printf("\n");
	}
	printf("\n");*/

	dfs(0, 0);
	return 0;
}