#include <bits/stdc++.h>


#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
using namespace std;


int main()
{
	int t;
	cin >>t;
	array<array<int,10>, 10> ba;
	rep(i,10) rep(j,10) cin >>ba[i][j];
	
	vector<vector<array<int, 2>>> mdl={
		{{0,0},{1,0}, {1,-1}, {1,1},{2,0}},
		{{0,0},{1,1},{0,1},{0,2},{1,0},{1,2},{2,0},{2,1},{2,2}},
		{{0,0},{2,0},{1,-1},{1,0},{1,1},{2,-2},{2,-1},{2,1},{2,2},
		 {3,-1},{3,0},{3,1},{4,0}}
	};
	
	int gk=0;
	rep(i,10) rep(j,10) gk+=ba[i][j];
	
	vector<int> cnd;
	rep(a,t+1) rep(b,t+1) rep(c,t+1){
		if(a+b+c==t && 5*a + 9*b + 13*c == gk){
		
			string s = string(a, '0') + string(b, '1') + string(c, '2');
			do {
				auto wa = ba;
				vector<int> ans;
				bool ok=1; 
				rep(i,t){
					if(!ok) break;
					int my,mx;
					rep(y,10) rep(x,10) if(wa[y][x]>0){my=y; mx=x; y=100; break;}
					ans.push_back(my*100+mx);
					int cr=s[i]-'0';
					
					for(auto r: mdl[cr]) if(ok){
						int ny=r[0]+my, nx=r[1]+mx;
						if(ny<0 || ny>=10 || nx<0 || nx>=10){ ok=0; break;}
						if(wa[ny][nx] >0 ) wa[ny][nx]--;
						else if(wa[ny][nx] <1 ){ ok=0; break;}
					}
				}
				bool ng=0;
				rep(y,10) rep(x,10) if(wa[y][x] !=0) ng=1;
				//rep(y,10) rep(x,10) printf("%d%s",wa[y][x],(x==9? "\n":" "));
				if(!ng){
					rep(i,t){
						printf("%d %d %d\n", 
							ans[i]%100 + mdl[s[i]-'0'][1][1],
							ans[i]/100 + mdl[s[i]-'0'][1][0],
							s[i]-'0'+1);
					}
					return 0;
				}
			} while ( next_permutation(s.begin(), s.end()) );
		}
	}
	return 0;
}