#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>


using namespace std;
const int MOD = 1000000009; // check!!!
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

const int MAX_H = 10;
const int MAX_W = 10;

int n;
int a[MAX_H][MAX_W];
struct P{
	int w,h,c;
	P(){}
	P(int w,int h,int c) : w(w),h(h),c(c) {}
};

P ans[12];
vector<int> dw[3],dh[3];
int dw_min[] = {-1,0,-2};
int dw_max[] = {1,2,2};
int dw_md[] = {0,1,0};
int dh_min[] = {0,0,0};
int dh_max[] = {2,2,4};
int dh_md[] = {1,1,2};

void init(){
	static int dx1[] = {0,-1,0,1,0};
	static int dy1[] = {0,1,1,1,2};
	static int dx2[] = {0,1,2,0,1,2,0,1,2};
	static int dy2[] = {0,0,0,1,1,1,2,2,2};
	static int dx3[] = {0,-1,0,1,-2,-1,0,1,2,-1,0,1,0};
	static int dy3[] = {0,1,1,1,2,2,2,2,2,3,3,3,4};

	FOR(i,5) dw[0].push_back(dx1[i]), dh[0].push_back(dy1[i]);
	FOR(i,9) dw[1].push_back(dx2[i]), dh[1].push_back(dy2[i]);
	FOR(i,13) dw[2].push_back(dx3[i]), dh[2].push_back(dy3[i]);
}

bool vaild(int x,int h,int w){
	if(0 <= w + dw_min[x] && w + dw_max[x] < MAX_W &&
	   0 <= h + dh_min[x] && h + dh_max[x] < MAX_H){
		FOR(i,sz(dw[x])){
			if(a[h + dh[x][i]][w + dw[x][i]] == 0)
				return false;
		}
		return true;
	} else {
		return false;
	}
}

void erase(int x,int h,int w){
	FOR(i,sz(dw[x])) a[h + dh[x][i]][w + dw[x][i]]--;
}

void redraw(int x,int h,int w){
	FOR(i,sz(dw[x])) a[h + dh[x][i]][w + dw[x][i]]++;
}

inline void hw_next(int &h,int &w){
	while(h < MAX_H){
		while(w < MAX_W){
			if(a[h][w] != 0) return;
			w++;
		}
		h++,w = 0;
	}
}

bool dfs(int h,int w,int sn,int sm){
	if(sn == n || sm == 0){
		return sm == 0 && sn == n;
	}

	if(a[h][w] != 0){
		FOR(i,3) if(sn < n && sm - sz(dw[i]) >= 0 && vaild(i,h,w)) {
			erase(i,h,w);
			ans[sn] = P(w + dw_md[i],h + dh_md[i],i+1);
			bool ret = dfs(h,w,sn + 1,sm - sz(dw[i]));
			redraw(i,h,w);
			if(ret) return true;
		}
	} else {
		hw_next(h,w);
		bool ret = dfs(h,w,sn,sm);
		if(ret) return true;
	}

	return false;
}

int main(){
	init();
	cin>>n;
	FOR(i,MAX_H) FOR(j,MAX_W) cin>>a[i][j];
	int sm = 0; 
	FOR(i,MAX_H) FOR(j,MAX_W) sm += a[i][j];

	dfs(0,0,0,sm);

	FOR(i,n){
		printf("%d %d %d\n",ans[i].w,ans[i].h,ans[i].c);
	}

	return 0;
}