#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int map[10][10];
int line[10] = {0};
vector<int> cx;		//x座標
vector<int> cy;		//y座標
vector<int> cz;		//大きさ
int dx[13] = { 0,-1, 0, 1, 0,-1,-1, 1, 1, 0,-2, 2, 0};
int dy[13] = {-1, 0, 0, 0, 1,-1, 1,-1, 1,-2, 0, 0, 2};
int ds[4] = { 0, 5, 9,13};

int saiki( int nokori[3], int x, int y, int size ) {
	if ( nokori[0] + nokori[1] + nokori[2] == 0 ) {
		for ( int i = 0; i < 10; i++ ) {
			for ( int j = 0; j < 10; j++ ) {
				if ( map[j][i] != 0 ) return 0;
			}
		}
		return 1;
	}
	for ( int i = y; i < 9; i++ ) {
		if ( i >= 3 ) {
			if ( line[ i-3 ] > 0 ) return 0;
		}
		for ( int j = x; j < 9; j++ ) {
			cx.push_back(j);
			cy.push_back(i);
			for ( int k = size; k < 3; k++ ) {
				bool f = true;
				for ( int l = 0 ; l < ds[k+1] ; l++ ) {
					if ( map[ j+dx[l] ][ i+dy[l] ] <= 0 ) f = false;
					map[ j+dx[l] ][ i+dy[l] ]--;
					line[ i+dy[l] ]--;
				}
				if ( f ) {
					cz.push_back( k+1 );
					nokori[k]--;
					if ( saiki( nokori, j, i, k ) ) return 1;
					nokori[k]++;
					cz.pop_back();
				}
				for ( int l = 0 ; l < ds[k+1] ; l++ ) {
					map[ j+dx[l] ][ i+dy[l] ]++;
					line[ i+dy[l] ]++;
				}
				if ( f == false ) break;
			}
			cx.pop_back();
			cy.pop_back();
			size = 0;
		}
		x = 1;
	}
	return 0;
}

int main(){
	int n;
	cin >> n;
	int sum = 0;
	for ( int i = 0; i < 10; i++ ) {
		for ( int j = 0; j < 10; j++ ) {
			cin >> map[j][i];
			line[i] += map[j][i];
			sum += map[j][i];
		}
	}
	int nokori[3] = {0};
	nokori[1] = n;
	if ( sum > n * 9 ) {
		nokori[2] = ( sum - n * 9 ) / 4;
		nokori[1] -= nokori[2];
	}else if ( sum < n * 9 ) {
		nokori[0] = ( n * 9 - sum ) / 4;
		nokori[1] -= nokori[0];
	}
	for ( int i = 0; i <= nokori[1] / 2; i++ ) {
		if ( saiki( nokori, 1, 1, 0 ) ) break;
		nokori[0]++;
		nokori[1]-=2;
		nokori[2]++;
	}
	for ( int i = 0; i < n; i++ ) {
		cout << cx[i] << " " << cy[i] << " " << cz[i] << endl;
	}
	return 0;
}