#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>

#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) (v).begin(), (v).end()
#define MP make_pair

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> P;
typedef vector<P> vp;

void pp(vi v){
	rep(i, v.size()){
		cout << v[i] << ' ';
	}
	cout << endl;
}

void pp(vector<string> v){
	rep(i, v.size()){
		cout << v[i] << endl;
	}
}

void pp(int (*v)[20], int size = 20){
	rep(i, size){
		rep(j, size){
			cout << v[i][j] << ' ';
		}
		cout << endl;
	}
}

void pp(char (*v)[80], int size = 30){
	rep(i, size){
		rep(j, size){
			cout << v[i][j];
		}
		cout << endl;
	}
}

int board[4][20][20];

int dx[] = {0, -1, 1, 0, 0, 1, 1, -1, -1, 0, 0, -2, 2};
int dy[] = {0, 0, 0, 1, -1, 1, -1, 1, -1, -2, 2, 0, 0};

void drops(int x, int y, int d = 1){
	rep(i, 4+1) board[1][y+dy[i]][x+dx[i]] += d;
}

void dropm(int x, int y, int d = 1){
	rep(i, 8+1) board[2][y+dy[i]][x+dx[i]] += d;
}

void dropl(int x, int y, int d = 1){
	rep(i, 12+1) board[3][y+dy[i]][x+dx[i]] += d;
}

void dropink(int x, int y, int d = 1){
	board[0][y][x] += d;
	drops(x, y, d);
	dropm(x, y, d);
	dropl(x, y, d);
}

int dropnum;

bool solve(stack<pair<P, int> > &sp){
	FOR(i, 5, 15){
		FOR(j, 5, 15){
			if(board[0][i][j] < 0) return false;
		}
	}

	if(sp.size() == dropnum){
		FOR(i, 5, 15){
			FOR(j, 5, 15){
				if(board[0][i][j] != 0) return false;
			}
		}
		return true;
	}

	for(int k = 3; k >= 1; k--){
		FOR(i, 5, 15){
			FOR(j, 5, 15){
				if(board[k][i][j] >= k*4){
					// rep(i, k*4) board[k][y+dy[i]][x+dx[i]] += d;
					rep(m, k*4+1) dropink(j+dy[m], i+dx[m], -1);
					
					sp.push(MP(MP(j, i), k));
					if(solve(sp) == true) return true;
					sp.pop();
					rep(m, k*4+1) dropink(j+dy[m], i+dx[m], 1);
				}
			}
		}
	}

}

int main(){
	cin >> dropnum;
	FOR(i, 5, 15){
		FOR(j, 5, 15){
			int n;
			cin >> n;
//			cin >> board[0][i][j];
			if(n)dropink(j, i, n);
		}
	}

	//rep(i, 4){
	//	char* s[] = {"board", "small", "midd", "large"};
	//	cout<< s[i] << endl;
	//	pp(board[i]);
	//	cout << endl;
	//}

	stack<pair<P, int> > sp;

	if(solve(sp)){
		while(!sp.empty()){
			pair<P, int> p = sp.top();
			sp.pop();
			cout << p.first.first-5 << ' ' << p.first.second-5 << ' ' << p.second << endl;

		}
	}

	return 0;
}