#include <iostream>
#include <cstdio>
using namespace std;

#define N 10

int cloth[N][N];
int X[12], Y[12], type[12];
int n;
bool finish = false;

bool checkSmall(int x, int y) {
	if(x - 1 < 0 || x + 1 >= N || y + 2 >= N) return false;
	if(cloth[y][x] == 0) return false;
	if(cloth[y + 1][x - 1] == 0) return false;
	if(cloth[y + 1][x] == 0) return false;
	if(cloth[y + 1][x + 1] == 0) return false;
	if(cloth[y + 2][x] == 0) return false;
	return true;
}

bool checkMedium(int x, int y) {
	if(x + 2 >= N || y + 2 >= N) return false;
	if(cloth[y][x] == 0) return false;
	if(cloth[y][x + 1] == 0) return false;
	if(cloth[y][x + 2] == 0) return false;
	if(cloth[y + 1][x] == 0) return false;
	if(cloth[y + 1][x + 1] == 0) return false;
	if(cloth[y + 1][x + 2] == 0) return false;
	if(cloth[y + 2][x] == 0) return false;
	if(cloth[y + 2][x + 1] == 0) return false;
	if(cloth[y + 2][x + 2] == 0) return false;
	return true;
}

bool checkBig(int x, int y) {
	if(x - 2 < 0 || x + 2 >= N || y + 4 >= N) return false;
	if(cloth[y][x] == 0) return false;
	if(cloth[y + 1][x - 1] == 0) return false;
	if(cloth[y + 1][x] == 0) return false;
	if(cloth[y + 1][x + 1] == 0) return false;
	if(cloth[y + 2][x - 2] == 0) return false;
	if(cloth[y + 2][x - 1] == 0) return false;
	if(cloth[y + 2][x] == 0) return false;
	if(cloth[y + 2][x + 1] == 0) return false;
	if(cloth[y + 2][x + 2] == 0) return false;
	if(cloth[y + 3][x - 1] == 0) return false;
	if(cloth[y + 3][x] == 0) return false;
	if(cloth[y + 3][x + 1] == 0) return false;
	if(cloth[y + 4][x] == 0) return false;
	return true;
}

void dropSmall(int x, int y) {
	cloth[y][x] -= 1;
	cloth[y + 1][x - 1] -= 1;
	cloth[y + 1][x] -= 1;
	cloth[y + 1][x + 1] -= 1;
	cloth[y + 2][x] -= 1;
}

void dropMedium(int x, int y) {
	cloth[y][x] -= 1;
	cloth[y][x + 1] -= 1;
	cloth[y][x + 2] -= 1;
	cloth[y + 1][x] -= 1;
	cloth[y + 1][x + 1] -= 1;
	cloth[y + 1][x + 2] -= 1;
	cloth[y + 2][x] -= 1;
	cloth[y + 2][x + 1] -= 1;
	cloth[y + 2][x + 2] -= 1;
}

void dropBig(int x, int y) {
	cloth[y][x] -= 1;
	cloth[y + 1][x - 1] -= 1;
	cloth[y + 1][x] -= 1;
	cloth[y + 1][x + 1] -= 1;
	cloth[y + 2][x - 2] -= 1;
	cloth[y + 2][x - 1] -= 1;
	cloth[y + 2][x] -= 1;
	cloth[y + 2][x + 1] -= 1;
	cloth[y + 2][x + 2] -= 1;
	cloth[y + 3][x - 1] -= 1;
	cloth[y + 3][x] -= 1;
	cloth[y + 3][x + 1] -= 1;
	cloth[y + 4][x] -= 1;
}

void resetSmall(int x, int y) {
	cloth[y][x] += 1;
	cloth[y + 1][x - 1] += 1;
	cloth[y + 1][x] += 1;
	cloth[y + 1][x + 1] += 1;
	cloth[y + 2][x] += 1;
}

void resetMedium(int x, int y) {
	cloth[y][x] += 1;
	cloth[y][x + 1] += 1;
	cloth[y][x + 2] += 1;
	cloth[y + 1][x] += 1;
	cloth[y + 1][x + 1] += 1;
	cloth[y + 1][x + 2] += 1;
	cloth[y + 2][x] += 1;
	cloth[y + 2][x + 1] += 1;
	cloth[y + 2][x + 2] += 1;
}

void resetBig(int x, int y) {
	cloth[y][x] += 1;
	cloth[y + 1][x - 1] += 1;
	cloth[y + 1][x] += 1;
	cloth[y + 1][x + 1] += 1;
	cloth[y + 2][x - 2] += 1;
	cloth[y + 2][x - 1] += 1;
	cloth[y + 2][x] += 1;
	cloth[y + 2][x + 1] += 1;
	cloth[y + 2][x + 2] += 1;
	cloth[y + 3][x - 1] += 1;
	cloth[y + 3][x] += 1;
	cloth[y + 3][x + 1] += 1;
	cloth[y + 4][x] += 1;
}

void solve(int count) {
	if(count < n) {
		int i, j;
		i = 0;
		while(i < N) {
			j = 0;
			while(j < N) {
				if(cloth[i][j] != 0) {
					if(checkSmall(j, i)) {
						dropSmall(j, i);
						X[count] = j;
						Y[count] = i + 1;
						type[count] = 1;
						solve(count + 1);
						resetSmall(j, i);
					}
					if(finish) return;
					if(checkMedium(j, i)) {
						dropMedium(j, i);
						X[count] = j + 1;
						Y[count] = i + 1;
						type[count] = 2;
						solve(count + 1);
						resetMedium(j, i);
					}
					if(finish) return;
					if(checkBig(j, i)) {
						dropBig(j, i);
						X[count] = j;
						Y[count] = i + 2;
						type[count] = 3;
						solve(count + 1);
						resetBig(j, i);
					}
					if(finish) return;
					return;
				}
				++j;
			}
			++i;
		}
	} else {
		for(int i = 0; i < N; ++i) {
			for(int j = 0; j < N; ++j) {
				if(cloth[i][j] != 0) return;
			}
		}
		finish = true;
	}
}

int main(void) {
	cin >> n;
	
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < N; ++j) {
			cin >> cloth[i][j];
		}
	}
	
	solve(0);
	
	if(finish) {
		for(int i = 0; i < n; ++i) {
			printf("%d %d %d\n", X[i], Y[i], type[i]);
		}
	} else {
		cout << "error" << endl;
	}
	
	return 0;
}
