#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,2,0,-2,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0,2,0,-2};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int Y[100];
int X[100];
int T[100];
int SZ;
int n;
bool F;
bool checkS(int stage[10][10],int y,int x,int type){
	int cy = y + 1;
	int cx = x;
	if(type < 0){
		if(stage[cy][cx] == 0)return false;
		rep(i,4){
			if(stage[cy+dy[i]][cx+dx[i]] == 0)return false;
		}
	}
	stage[cy][cx] += type;
	rep(i,4){
		stage[cy+dy[i]][cx+dx[i]] += type;
	}
	return true;
}
bool checkM(int stage[10][10],int y,int x,int type){
	int cy = y + 1;
	int cx = x + 1;
	if(type < 0){
		if(stage[cy][cx] == 0)return false;
		rep(i,8){
			if(stage[cy+dy[i]][cx+dx[i]] == 0)return false;
		}
	}
	stage[cy][cx] += type;
	rep(i,8){
		stage[cy+dy[i]][cx+dx[i]] += type;
	}
	return true;	
}
bool checkL(int stage[10][10],int y,int x,int type){
	int cy = y + 2;
	int cx = x;
	if(type < 0){
		if(stage[cy][cx] == 0)return false;
		rep(i,12){
			if(stage[cy+dy[i]][cx+dx[i]] == 0)return false;
		}
	}
	stage[cy][cx] += type;
	rep(i,12){
		stage[cy+dy[i]][cx+dx[i]] += type;
	}
	return true;
}
void solve(int y,int x,int len,int stage[10][10]){
	if(F)return ;
	if(x == 10){
		y++;
		x = 0;
	}
	if(y == 10){
		if(len == n){
			SZ = len;
			rep(i,SZ){
		    	printf("%d %d %d\n",X[i],Y[i],T[i]);
		    }
			F = true;
		}
		return ;
	}
	if(stage[y][x] == 0){
		solve(y,x+1,len,stage);
	}
	if(checkS(stage,y,x,-1)){
		Y[len] = y+1;
		X[len] = x;
		T[len] = 1;
		solve(y,x+1,len+1,stage);
		solve(y,x,len+1,stage);
		checkS(stage,y,x,1);
		Y[len] = 0;
		X[len] = 0;
		T[len] = 0;
	}
	if(checkM(stage,y,x,-1)){
		Y[len] = y+1;
		X[len] = x+1;
		T[len] = 2;
		solve(y,x+1,len+1,stage);
		solve(y,x,len+1,stage);
		checkM(stage,y,x,1);
		Y[len] = 0;
		X[len] = 0;
		T[len] = 0;
	}
	if(checkL(stage,y,x,-1)){
		Y[len] = y+2;
		X[len] = x;
		T[len] = 3;
		solve(y,x+1,len+1,stage);
		solve(y,x,len+1,stage);
		checkL(stage,y,x,1);
		Y[len] = 0;
		X[len] = 0;
		T[len] = 0;
	}
	return ;
}
int main(){
    int stage[10][10]={{0}};
    scanf("%d",&n);
    rep(i,10){
        rep(j,10){
            scanf("%d",&stage[i][j]);
        }
    }
    solve(0,0,0,stage);
    return 0;
}