#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
/*
6
0 0 1 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 0 0
0 0 1 1 1 3 1 1 0 0
0 0 1 1 3 1 1 1 0 0
0 0 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 0 0
*/

int n;
int f[10][10];
int drops[10][10][4];

void debug(){
	for( int y = 0; y < 10; y++ ){
		for( int x = 0; x < 10; x++ ){
			printf( "%d ", f[y][x] );
		}
		cout << endl;
	}
	cout << endl;
	cout << endl;
}

bool check(){
	for( int y = 0; y < 10; y++ ){
		for( int x = 0; x < 10; x++ ){
			if( f[y][x] != 0 ) return false;
		}
	}
	return true;
}

bool drop1( int x, int y ){
	if( x == 0 || x == 9 || y >= 8 ) return false;
	if( f[y][x] == 0 ) return false;
	if( f[y+1][x-1] == 0 || f[y+1][x] == 0 || f[y+1][x+1] == 0 ) return false;
	if( f[y+2][x] == 0 ) return false;
	f[y][x]--; 
	f[y+1][x-1]--; f[y+1][x]--; f[y+1][x+1]--;
	f[y+2][x]--;
	drops[y+1][x][1]++;
	return true;
}

bool drop2( int x, int y ){
	if( x >= 8 || y >= 8 ) return false;
	if( f[y][x] == 0 || f[y][x+1] == 0 || f[y][x+2] == 0 ) return false;
	if( f[y+1][x] == 0 || f[y+1][x+1] == 0 || f[y+1][x+2] == 0 ) return false;
	if( f[y+2][x] == 0 || f[y+2][x+1] == 0 || f[y+2][x+2] == 0 ) return false;
	f[y][x]--; f[y][x+1]--; f[y][x+2]--;
	f[y+1][x]--; f[y+1][x+1]--; f[y+1][x+2]--;
	f[y+2][x]--; f[y+2][x+1]--; f[y+2][x+2]--;
	drops[y+1][x+1][2]++;
	return true;
}

bool drop3( int x, int y ){
	if( x < 2 || x > 7 || y > 5 ) return false;
	if( f[y][x] == 0 ) return false;
	if( f[y+1][x-1] == 0 || f[y+1][x] == 0 || f[y+1][x+1] == 0 ) return false;
	if( f[y+2][x-2] == 0 || f[y+2][x-1] == 0 || f[y+2][x] == 0 || f[y+2][x+1] == 0 || f[y+2][x+2] == 0) return false;
	if( f[y+3][x-1] == 0 || f[y+3][x] == 0 || f[y+3][x+1] == 0 ) return false;
	if( f[y+4][x] == 0 ) return false;
	f[y][x]--; 
	f[y+1][x-1]--; f[y+1][x]--; f[y+1][x+1]--;
	f[y+2][x-2]--; f[y+2][x-1]--; f[y+2][x]--; f[y+2][x+1]--; f[y+2][x+2]--;
	f[y+3][x-1]--; f[y+3][x]--; f[y+3][x+1]--;
	f[y+4][x]--;
	drops[y+2][x][3]++;
	return true;
}

void remove1( int x, int y ){
	f[y][x]++; 
	f[y+1][x-1]++; f[y+1][x]++; f[y+1][x+1]++;
	f[y+2][x]++;
	drops[y+1][x][1]--;
}

void remove2( int x, int y ){
	f[y][x]++; f[y][x+1]++; f[y][x+2]++;
	f[y+1][x]++; f[y+1][x+1]++; f[y+1][x+2]++;
	f[y+2][x]++; f[y+2][x+1]++; f[y+2][x+2]++;
	drops[y+1][x+1][2]--;
}
void remove3( int x, int y ){
	f[y][x]++; 
	f[y+1][x-1]++; f[y+1][x]++; f[y+1][x+1]++;
	f[y+2][x-2]++; f[y+2][x-1]++; f[y+2][x]++; f[y+2][x+1]++; f[y+2][x+2]++;
	f[y+3][x-1]++; f[y+3][x]++; f[y+3][x+1]++;
	f[y+4][x]++;
	drops[y+2][x][3]--;
}

bool rec( int c ){
	if( c == 0 ){
		return check();
	}

	bool find = false;
	for( int y = 0; y < 10 && !find; y++ ){
		for( int x = 0; x < 10 && !find; x++ ){
			if( f[y][x] == 0 ) continue;
			find = true;
			if( drop1( x, y ) ){
				if( rec( c - 1 ) ) return true;
				remove1( x, y );
			}
			if( drop2( x, y ) ){
				if( rec( c - 1 ) ) return true;
				remove2( x, y );
			}
			if( drop3( x, y ) ){
				if( rec( c - 1 ) ) return true;
				remove3( x, y );
			}
			
		}
	}

	return false;
}
int main() {
//	ifstream in( "in.txt" );
//	ofstream out( "out.txt" );
	istream& in = cin;

	// 入力
	in >> n;
	for( int y = 0; y < 10; y++ ){
		for( int x = 0; x < 10; x++ ){
			in >> f[y][x];
		}
	}

	rec( n );

	// 出力
	while( true ){
		bool find = false;
		for( int y = 0; y < 10; y++ ){
			for( int x = 0; x < 10; x++ ){
				for( int t = 1; t <= 3; t++ ){
					if( drops[y][x][t] == 0 ) continue;
					printf( "%d %d %d\n", x, y, t );
					drops[y][x][t]--;
					find = true;
				}
			}
		}
		if( !find ) break;
	}

	return 0;
}

Measured memory_bytes: 1152