#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

void copy_ban(li src[10][10], li dst[10][10]){
	rep(i,10){
		rep(j,10)dst[i][j]=src[i][j];
	}
}

bool zero(li ban[10][10]){
	li res=0;
	rep(i,10){
		rep(j,10)res+=abs(ban[i][j]);
	}
	return res<1;
}

bool can_put(li ban[10][10], li x, li y, li type){
	li rad=2;
	if(type<2)rad=1;
	if(x<rad || y<rad || x>9-rad || y>9-rad)return false;
	
	if(ban[x][y]==0 || ban[x-1][y]==0 || ban[x+1][y]==0 || ban[x][y-1]==0 || ban[x][y+1]==0)return false;
	if(type==0)return true;
	
	if(ban[x-1][y-1]==0 || ban[x-1][y+1]==0 || ban[x+1][y-1]==0 || ban[x+1][y+1]==0)return false;
	if(type==1)return true;
	
	if(ban[x-2][y]==0 || ban[x+2][y]==0 || ban[x][y-2]==0 || ban[x][y+2]==0)return false;
	return true;
}

void put_ban(li ban[10][10], li new_ban[10][10], li y, li x, li type){
	copy_ban(ban,new_ban);
	new_ban[y][x]-=1;
	new_ban[y-1][x]-=1;
	new_ban[y+1][x]-=1;
	new_ban[y][x-1]-=1;
	new_ban[y][x+1]-=1;
	if(type==0)return;
	new_ban[y-1][x-1]-=1;
	new_ban[y+1][x-1]-=1;
	new_ban[y-1][x+1]-=1;
	new_ban[y+1][x+1]-=1;
	if(type==1)return;
	new_ban[y-2][x]-=1;
	new_ban[y+2][x]-=1;
	new_ban[y][x-2]-=1;
	new_ban[y][x+2]-=1;
}

void print_ban(li ban[10][10]){
	rep(i,10){
		rep(j,10)cout<<ban[i][j]<<" ";
		puts("");
	}
		puts("");
}

vector<vector<li> > solve(li ban[10][10], li num){
	if(num==0 && zero(ban))return vector<vector<li> >(0);
	else if(num==0)return vector<vector<li> >(1,vector<li>(3,-1));
	
	//print_ban(ban);
	
	vector<li> newPoint(3,0);
	
	li new_ban[10][10];
	
	rep(i,10){
		rep(j,10){
			if(ban[i][j]>0){
				if(can_put(ban, i+1, j, 0)){
					//cout<<"small can put at ("<<i+1<<" , "<<j<<")"<<endl;
					put_ban(ban,new_ban, i+1, j, 0);
					vector<vector<li> > next_res=solve(new_ban, num-1);
					if(sz(next_res)!=1 || (sz(next_res)>0 && next_res[0][0]>=0)){
						newPoint[0]=i+1;
						newPoint[1]=j;
						newPoint[2]=0;
						next_res.pb(newPoint);
						return next_res;
					}
				}
				if(can_put(ban, i+1, j+1, 1)){
					put_ban(ban,new_ban, i+1, j+1, 1);
					vector<vector<li> > next_res=solve(new_ban, num-1);
					if(sz(next_res)!=1 || (sz(next_res)>0 && next_res[0][0]>=0)){
						newPoint[0]=i+1;
						newPoint[1]=j+1;
						newPoint[2]=1;
						next_res.pb(newPoint);
						return next_res;
					}
				}
				if(can_put(ban, i+2, j, 2)){
					put_ban(ban,new_ban, i+2, j, 2);
					vector<vector<li> > next_res=solve(new_ban, num-1);
					if(sz(next_res)!=1 || (sz(next_res)>0 && next_res[0][0]>=0)){
						newPoint[0]=i+2;
						newPoint[1]=j;
						newPoint[2]=2;
						next_res.pb(newPoint);
						return next_res;
					}
				}
				return vector<vector<li> >(1,vector<li>(3,-1));
				
				break;
			}
		}
	}
	
	return vector<vector<li> >(0);
}

int main(){
	li num;
	li ban[10][10];
	vector<vector<li> >res;
	cin>>num;
	rep(i,10){
		rep(j,10)cin>>ban[i][j];
	}
	
	res=solve(ban,num);
	
	rep(i,sz(res)){
		cout<<res[i][1]<<" "<<res[i][0]<<" "<<res[i][2]+1<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1236