#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int smlx[]={1, -1, 0, 0, 0};
int smly[]={0, 0, 1, -1, 0};
int medx[] = {0, -1, 1, 0, -1, 1, 0, -1, 1};
int medy[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int lrgx[] = { 0,  0, 0, 0, 0, -2, -1, 1, 2, 1, 1, -1, -1};
int lrgy[] = {-2, -1, 0, 1, 2,  0,  0, 0, 0, 1, -1, 1, -1};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

bool in(int i, int j, int dx, int dy) {
    return i+dx >= 0 && i+dx < 10 && j+dy >= 0 && j+dy < 10;
}

bool ans;
bool check1[10][10], check2[10][10], check3[10][10];
bool solve(int n, vector< vector<int> > brd, vector< pair<pii, int> > p, set< vector< vector<int> > > &s) {
    if(ans) return false;
    if(s.count(brd)) return false;
    if(n == 0) {
        rep(i,0,10) rep(j,0,10) if(brd[i][j]) return false;
        ans = true;
        rep(i,0,p.size()) {
            printf("%lld %lld %lld\n", p[i].fr.fr, p[i].fr.sc, p[i].sc);
        }
        return true;
    }

    repq(i,1,8) repq(j,1,8) {
        if(brd[i][j] != 0) {
            bool ok1 = true, ok2 = true, ok3 = true;
            // small
            if(check1[i][j]) ok1 = false;
            else rep(k,0, 5) if(!in(i, j, smlx[k], smly[k]) || brd[i+smlx[k]][j+smly[k]] == 0) ok1 = false;
            // medium
            if(check2[i][j]) ok2 = false;
            else rep(k,0, 9) if(!in(i, j, medx[k], medy[k]) || brd[i+medx[k]][j+medy[k]] == 0) ok2 = false;
            // large
            if(check3[i][j]) ok3 = false;
            else rep(k,0,13) if(!in(i, j, lrgx[k], lrgy[k]) || brd[i+lrgx[k]][j+lrgy[k]] == 0) ok3 = false;

            if(ok1) {
                rep(k,0, 5) brd[i+smlx[k]][j+smly[k]]--;
                vector< pair<pii, int> > temp = p;
                temp.pb(make_pair(pii(j, i), 1));
                if(!solve(n-1, brd, temp, s)) s.insert(brd);
                rep(k,0, 5) brd[i+smlx[k]][j+smly[k]]++;
            }

            if(ok2) {
                rep(k,0, 9) brd[i+medx[k]][j+medy[k]]--;
                vector< pair<pii, int> > temp = p;
                temp.pb(make_pair(pii(j, i), 2));
                if(!solve(n-1, brd, temp, s)) s.insert(brd);
                rep(k,0, 9) brd[i+medx[k]][j+medy[k]]++;
            }

            if(ok3) {
                rep(k,0,13) brd[i+lrgx[k]][j+lrgy[k]]--;
                vector< pair<pii, int> > temp = p;
                temp.pb(make_pair(pii(j, i), 3));
                if(!solve(n-1, brd, temp, s)) s.insert(brd);
                rep(k,0,13) brd[i+lrgx[k]][j+lrgy[k]]++;
            }
        }
    }
    return false;
}

signed main() {
    int n; cin >> n;
    ans = false;
    vector< vector<int> > board(10, vector<int>(10, 0));
    rep(i,0,10) rep(j,0,10) scanf("%lld", &board[i][j]);

    memset(check1, false, sizeof(check1));
    memset(check2, false, sizeof(check2));
    memset(check3, false, sizeof(check3));
    rep(i,0,10) rep(j,0,10) {
        rep(k,0, 5) if(!in(i, j, smlx[k], smly[k]) || board[i+smlx[k]][j+smly[k]] == 0) check1[i][j] = true;
        rep(k,0, 9) if(!in(i, j, medx[k], medy[k]) || board[i+medx[k]][j+medy[k]] == 0) check2[i][j] = true;
        rep(k,0,13) if(!in(i, j, lrgx[k], lrgy[k]) || board[i+lrgx[k]][j+lrgy[k]] == 0) check3[i][j] = true;
    }
    set< vector< vector<int> > > s;
    if(!ans) bool k = solve(n, board, {}, s);
    return 0;
}