#include <cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int dx1[]={1,0,1,2,1};
const int dy1[]={0,1,1,1,2};
const int dx2[]={0,1,2,0,1,2,0,1,2};
const int dy2[]={0,0,0,1,1,1,2,2,2};
const int dx3[]={2,1,2,3,0,1,2,3,4,1,2,3,2};
const int dy3[]={0,1,1,1,2,2,2,2,2,3,3,3,4};

int n1,n2,n3;
int cloth[10][10];

bool dfs1(int i,int j){
	if(n1==0) return true;

	if(i+2>=10) return false;
	if(j+2>=10) return dfs1(i+1,0);

	bool ok=true;
	rep(k,5) if(cloth[i+dy1[k]][j+dx1[k]]==0) ok=false;
	if(ok){
		rep(k,5) cloth[i+dy1[k]][j+dx1[k]]--;
		n1--;
		if(dfs1(i,j)){
			printf("%d %d 1\n",j+1,i+1);
			return true;
		}
		n1++;
		rep(k,5) cloth[i+dy1[k]][j+dx1[k]]++;
	}

	return dfs1(i,j+1);
}

bool dfs2(int i,int j){
	if(n2==0) return dfs1(0,0);

	if(i+2>=10) return false;
	if(j+2>=10) return dfs2(i+1,0);

	bool ok=true;
	rep(k,9) if(cloth[i+dy2[k]][j+dx2[k]]==0) ok=false;
	if(ok){
		rep(k,9) cloth[i+dy2[k]][j+dx2[k]]--;
		n2--;
		if(dfs2(i,j)){
			printf("%d %d 2\n",j+1,i+1);
			return true;
		}
		n2++;
		rep(k,9) cloth[i+dy2[k]][j+dx2[k]]++;
	}

	return dfs2(i,j+1);
}

bool dfs3(int i,int j){
	if(n3==0) return dfs2(0,0);

	if(i+4>=10) return false;
	if(j+4>=10) return dfs3(i+1,0);

	bool ok=true;
	rep(k,13) if(cloth[i+dy3[k]][j+dx3[k]]==0) ok=false;
	if(ok){
		rep(k,13) cloth[i+dy3[k]][j+dx3[k]]--;
		n3--;
		if(dfs3(i,j)){
			printf("%d %d 3\n",j+2,i+2);
			return true;
		}
		n3++;
		rep(k,13) cloth[i+dy3[k]][j+dx3[k]]++;
	}

	return dfs3(i,j+1);
}

int main(){
	int n; scanf("%d",&n);
	int sum=0;
	rep(i,10) rep(j,10) {
		scanf("%d",cloth[i]+j);
		sum+=cloth[i][j];
	}

	for(n1=0;n1<=n;n1++) for(n2=0;n1+n2<=n;n2++) {
		n3=n-n1-n2;
		if(5*n1+9*n2+13*n3==sum && dfs3(0,0)) return 0;
	}

	return 0;
}