#include <iostream>
#include <ostream>
#include <stack>
using namespace std;

enum tag_drop_sizes { small_drop = 1, middle_drop, large_drop };

static const int MARGIN = 2;
static const int H = 10, W = 10;

const int small[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}};
const int middle[5][5] = {{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}};
const int large[5][5] = {{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}};

const int small_size = 5, middle_size = 9, large_size = 13;

struct operation {
	int x;
	int y;
	int size;

	operation(int a, int b, int c) {
		x = a; y = b; size = c;
	}
};

int cloth[16][16];
int depth;
int total;
int num_large_drop, num_middle_drop, num_small_drop;
stack<operation> s;

bool add(int x, int y, const int drop_size[5][5]) {
	for(int i = 0; i < 5; i++) {
		for(int j = 0; j < 5; j++) {
			cloth[y + i][x + j] += drop_size[i][j];
		}
	}
	return true;
}

bool sub(int x, int y, const int drop_size[5][5]) {
	bool ret = true;
	for(int i = 0; i < 5; i++) {
		for(int j = 0; j < 5; j++) {
			if((cloth[y + i][x + j] -= drop_size[i][j]) < 0)
				ret = false;
		}
	}
	return ret;
}

void init() {
	depth = 0;
	for(int i = 0; i < 16; i++)
		for(int j = 0; j < 16; j++)
			cloth[i][j] = 0;
}

bool complete() {
	for(int i = 0; i < 16; i++)
		for(int j = 0; j < 16; j++)
			if(cloth[i][j])
				return false;
	return true;
}

bool solve(int x, int y) {
	bool tmp;

	if(depth == 0) {
		if(complete())
			return true;
		return false;
	}

	else if(y >= 10)
		return false;

	if((tmp = sub(x, y, large)) && num_large_drop > 0) {
		num_large_drop--;
		s.push(operation(x,y,large_drop));
		depth--;
		if(solve(x, y))
			return true;
		depth++;
		s.pop();
		num_large_drop++;
	}
	add(x, y, large);

	if((tmp = sub(x, y, middle)) && num_middle_drop > 0) {
		num_middle_drop--;
		s.push(operation(x,y,middle_drop));
		depth--;
		if(solve(x, y))
			return true;
		depth++;
		s.pop();
		num_middle_drop++;
	}
	add(x, y, middle);

	if((tmp = sub(x, y, small)) && num_small_drop > 0) {
		num_small_drop--;
		s.push(operation(x,y,small_drop));
		depth--;
		if(solve(x, y))
			return true;
		depth++;
		s.pop();
		num_small_drop++;
	}
	add(x, y, small);

	y += (x + 1) / 10;
	x = (x + 1) % 10;

	return solve(x, y);
}

int count_total() {
	int count = 0;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			count += cloth[MARGIN + i][MARGIN + j];
		}
	}

	return count;
}

void set_num() {
	static int i = 0, j = 0;
	for(; i < depth; i++, j = 0) {
		for(; j < depth - i; j++) {
			if(4 * i + 8 * j == total - 5 * depth) {
				num_small_drop = depth - i - j;
				num_middle_drop = i;
				num_large_drop = j;

				i++; j++;
				return;
			}
		}
	}
	return;
}

int main() {
	init();
	cin >> depth;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			cin >> cloth[i + MARGIN][j + MARGIN];
		}
	}

	total = count_total();

	while(1) {
		set_num();
		if(solve(0, 0)) {
			while(!s.empty()) {
				operation tmp = s.top();
				cout << tmp.x << " " << tmp.y << " " << tmp.size << endl;
				s.pop();
			}
			break;
		}
	}
}