#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,(n))
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n, m)
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

const int MAX_N = 1<<20;

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

bool outOfRange(int y,int x){
	if(x < 0 || x >= 10 || y < 0 || y >= 10) return true;
	return false;
}

struct Rog{
	int x, y, sz;
	Rog(){}
	Rog(int y, int x, int sz):x(x),y(y),sz(sz){}
};

int n;
vii in, tmp;
vector<Rog> ans;
bool f;

void calc(vii v, vector<Rog> r){
	//cout<<r.size()<<endl;
	if(r.size() > n || f) return;
	bool isAns = true;
	rep(i, 10){
		rep(j,10){
			if(v[i][j] > in[i][j]) return;
			else if(v[i][j] < in[i][j]){
				isAns = false;
			}
		}
	}
	if(isAns){
		ans = r;
		f = true;
		return;
	}
	bool out;
	int ny, nx;
	rep(i, 10){
		rep(j, 10){
			rep(k, 3){
				tmp = v;
				out = false;
				tmp[i][j]++;
				for(int l = 0; l <= k; l++){
					for(int m = 0; m < 4; m++){
						ny = i + dy[l][m], nx = j + dx[l][m];
						if(outOfRange(ny, nx)){
							out = true;
							break;
						}
						tmp[ny][nx]++;
					}
					if(out) break;
				}
				if(out) break;
				r.pb(Rog(i, j, k+1));
				calc(tmp, r);
				r.pop_back();
			}
		}
	}
}

int main(){
	cin>>n;
	vii v(10, vi(10, 0));
	vector<Rog> r;
	rep(i, 10){
		in.pb(vi(10));
		rep(j, 10){
			cin>>in[i][j];
		}
	}
	calc(v, r);
	for(int i = 0; i < ans.size(); i++){
		cout<<ans[i].x<<" "<<ans[i].y<<" "<<ans[i].sz<<endl;
	}
	//cout<<ans.size()<<" "<<f<<endl;
}