#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;


struct Drop{
	Drop( int _x, int _y, int _s ) : x( _x ), y( _y ), size( _s ){}
	int x;
	int y;
	int size;
};

const int DROP_POS_NUM = 13;

int offset[ DROP_POS_NUM ][ 2 ] = {
	{ 0, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 },
	{ 1, -1 }, { 1, 1 }, { -1, 1 }, { -1, -1 },
	{ 0, -2 }, { 2, 0 }, { 0, 2 }, { -2, 0 }
};

const int drop_size[] = {
	0, 5, 9, 13
};

const int drops[] = {
	0,
	( 1 << drop_size[ 1 ] ) - 1,
	( 1 << drop_size[ 2 ] ) - 1,
	( 1 << drop_size[ 3 ] ) - 1,
};

bool solve( vector< vector< int > >& field, vector< vector< int > >& memo, vector< Drop >& ans, int r, int pos, int sum )
{
	if( r == 0 && sum == 0 ){
		return true;
	}

	for( int p = pos; p < 10 * 10; ++p ){
		int x = p % 10 + 2;
		int y = p / 10 + 2;
		if( field[ y ][ x ] == 0 ) continue;
		for( int k = DROP_POS_NUM - 1; k > 0; --k ){
			int dx = x + offset[ k ][ 0 ];
			int dy = y + offset[ k ][ 1 ];
			for( int s = 3; s > 0; --s ){
				if( ( memo[ dy ][ dx ] & drops[ s ] ) == drops[ s ] ){
					vector< vector< int > > f = field;
					vector< vector< int > > m = memo;
					for( int l = 0; l < drop_size[ s ]; ++l ){
						int fx = dx + offset[ l ][ 0 ];
						int fy = dy + offset[ l ][ 1 ];
						f[ fy ][ fx ]--;
						if( f[ fy ][ fx ] == 0 ){
							for( int t = 0; t < DROP_POS_NUM; ++t ){
								int ex = fx + offset[ t ][ 0 ];
								int ey = fy + offset[ t ][ 1 ];
								int bit = 1;
								if( t != 0 ){
									int shift = t + ( ( t + 3 ) % 4 < 2 ? 2 : -2 );
									bit <<= shift;
								}
								m[ ey ][ ex ] &= ~bit;
							}
						}
					}
					if( solve( f, m, ans, r - 1, pos, sum - drop_size[ s ] ) ){
						ans.push_back( Drop( dx - 2, dy - 2, s ) );
						return true;
					}
				}
			}
		}
		return false;
	}

	return false;
}
 
int main()
{
	int n;
	while( cin >> n ){
		vector< vector< int > > field( 10 + 4, vector< int >( 10 + 4, 0 ) );
		int sum = 0;
		for( int i = 0; i < 10; ++i ){
			for( int j = 0; j < 10; ++j ){
				int a;
				cin >> a;
				field[ i + 2 ][ j + 2 ] = a;
				sum += a;
			}
		}

		vector< vector< int > > memo( 10 + 4, vector< int >( 10 + 4, 0 ) );
		for( int i = 2; i < 10 + 2; ++i ){
			for( int j = 2; j < 10 + 2; ++j ){
				int bits = 0;
				for( int k = 0; k < DROP_POS_NUM; ++k ){
					int x = j + offset[ k ][ 0 ];
					int y = i + offset[ k ][ 1 ];
					if( field[ y ][ x ] > 0 ){
						bits |= ( 1 << k );
					}
				}
				memo[ i ][ j ] = bits;
			}
		}

		vector< Drop > ans;
		solve( field, memo, ans, n, 0, sum );

		for( int i = 0; i < n; ++i ){
			cout << ans[ i ].x << " " << ans[ i ].y << " " << ans[ i ].size << endl;
		}
	}
	return 0;
}