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

int a[10][10];
int b[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 e0, int e1, int e2, int nokori, int size, int x, int y );

int kansu( int j, int i, int k, int e0, int e1, int e2, int m ) {
	if ( a[j][i] == 0 ) return 0;
	cx.push_back(j);
	cy.push_back(i);
	bool f = true;
	for ( int l = 0 ; l < ds[k+1] ; l++ ) {
		if ( a[ j+dx[l] ][ i+dy[l] ] <= 0 ) f = false;
		a[ j+dx[l] ][ i+dy[l] ]--;
		b[ i+dy[l] ]--;
		m--;
	}
	if ( f ) {
		cz.push_back(k+1);
		if ( saiki( e0, e1, e2, m, k, j, i ) ) return 1;
		cz.pop_back();
	}
	for ( int l = 0 ; l < ds[k+1] ; l++ ) {
		a[ j+dx[l] ][ i+dy[l] ]++;
		b[ i+dy[l] ]++;
	}
	cx.pop_back();
	cy.pop_back();
	return 0;
}

int saiki( int e0, int e1, int e2, int nokori, int size, int x, int y ) {
	if ( e0 + e1 + e2 == 0 ) {
		if ( nokori == 0 ) {
			for ( int i = 0; i < 10; i++ ) {
				for ( int j = 0; j < 10; j++ ) {
					if ( a[j][i] != 0 ) return 0;
				}
			}
			return 1;
		}
		return 0;
	}
	for ( int i = y; i < 9; i++ ) {
		if ( i >= 3 ) {
			if ( b[ i-3 ] > 0 ) return 0;
		}
		for ( int j = x; j < 9; j++ ) {
			if ( e0 > 0 && size <= 0 ) {
				if ( kansu( j, i, 0, e0-1, e1, e2, nokori ) ) return 1;
			}
			if ( e1 > 0 && size <= 1 ) {
				if ( kansu( j, i, 1, e0, e1-1, e2, nokori ) ) return 1;
			}
			if ( j==1 || j==8 || i==1 || i==8 ) continue;
			if ( e2 > 0 && size <= 2 ) {
				if ( kansu( j, i, 2, e0, e1, e2-1, nokori ) ) return 1;
			}
		}
		x = 1;
		size = 0;
	}
	return 0;
}

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