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

int pattern[ 4 ][ 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 }
	},
	{
		{ 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 }
	},
	{
		{ 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 }
	}
};

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

bool solve2( int p, vector< vector< int > >& map, vector< Drop >& ans )
{
	if( p == ans.size() ){
		return true;
	}

	int b, e, d, s = ans[ p ].size;
	switch( s ){
		case 1: case 2: b = 1, e = 9, d = 1; break;
		case 3:         b = 2, e = 8, d = 2; break;
	}
	for( int i = b; i < e; ++i ){
		bool ret = true;
		vector< vector< int > > m = map;
		for( int y = -d; y <= d; ++y ){
			for( int x = -d; x <= d; ++x ){
				int u = ans[ p ].x + x, v = i + y;
				if( pattern[ s ][ 2 + y ][ 2 + x ] > 0 ){
					if( m[ v ][ u ] <= 0 ){
						ret = false;
						break;
					}
				m[ v ][ u ]--;
				}
			}
			if( !ret ) break;
		}
		if( !ret ) continue;
		ret = solve2( p + 1, m, ans );
		if( ret ){
			ans[ p ].y = i;
			return true;
		}
	}

	return false;
}

bool solve( int n, int sum, vector< vector< int > >& map, vector< int >& col, vector< Drop >& ans )
{
	if( sum < 0 || ( n == 0 && sum != 0 ) ){
		return false;
	}
	if( n == 0 ){
		return solve2( 0, map, ans );
	}
	bool ret = false;
	for( int i = 3; i >= 1; --i ){
		switch( i ){
			case 3:
				for( int j = 2; j < 8; ++j ){
					vector< int > c = col;
					if( c[ j - 2 ] >= 1 && c[ j - 1 ]  >= 3 && c[ j ] >= 5 && c[ j + 1 ] >= 3 && c[ j + 2 ] >= 1 ){
						ans.push_back( Drop( i, j, -1 ) );
						c[ j - 2 ] -= 1, c[ j - 1 ] -= 3, c[ j ] -= 5, c[ j + 1 ] -= 3, c[ j + 2 ] -= 1;
						ret = solve( n - 1, sum - 13, map, c, ans );
						if( ret ) break;
						ans.pop_back();
					}
				}
				break;
			case 2:
				for( int j = 1; j < 9; ++j ){
					vector< int > c = col;
					if( c[ j - 1 ] >= 3 && c[ j ] >= 3 && c[ j + 1 ] >= 3 ){
						c[ j - 1 ] -= 3, c[ j ] -= 3, c[ j + 1 ] -= 3;
						ans.push_back( Drop( i, j, -1 ) );
						ret = solve( n - 1, sum - 9, map, c, ans );
						if( ret ) break;
						ans.pop_back();
					}
				}
				break;
			case 1:
				for( int j = 1; j < 9; ++j ){
					vector< int > c = col;
					if( c[ j - 1 ] >= 1 && c[ j ] >= 3 && c[ j + 1 ] >= 1 ){
						c[ j - 1 ] -= 1, c[ j ] -= 3, c[ j + 1 ] -= 1;
						ans.push_back( Drop( i, j, -1 ) );
						ret = solve( n - 1, sum - 5, map, c, ans );
						if( ret ) break;
						ans.pop_back();
					}
				}
				break;
		}
		if( ret ) return true;
	}
	return false;
}

int main()
{
	int n;
	while( cin >> n ){
		vector< vector< int > > map( 10, vector< int >( 10, 0 ) );
		vector< int > col( 10, 0 );
		int sum = 0;
		for( int i = 0; i < 10; ++i ){
			for( int j = 0; j < 10; ++j ){
				cin >> map[ i ][ j ];
				sum += map[ i ][ j ];
				col[ j ] += map[ i ][ j ];
			}
		}
		vector< Drop > ans;
		solve( n, sum, map, col, ans );
		for( int i = 0; i < (int)ans.size(); ++i ){
			cout << ans[ i ].x << " " << ans[ i ].y << " " << ans[ i ].size << endl;
		}
	}
	return 0;
}