#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
int A[10][10];
int N;
const int W = 10;
const int H = 10;
const int L = 13;

pair<int, int> next() {
    REP(y, H) REP(x, W) if(A[y][x] > 0) {
        return make_pair(x, y);
    }
    return make_pair(-1, -1);
}
int len[4] = {0, 5, 9, 13};
int dx[] = {
    0, 1, 0, -1, 0,  1, 1, -1, -1,  2, 0, -2, 0
};
int dy[] = {
    0, 0, 1, 0, -1,  1, -1, -1, 1,  0, 2, 0, -2
};
int r[3] = {1, 1, 2};

int ok(int cx, int cy) {
    REP(i, L) {
        int x = cx + dx[i];
        int y = cy + dy[i];
        if(x < 0 || W <= x) return i;
        if(y < 0 || H <= y) return i;
        if(A[y][x] == 0) return i;
    }
    return L;
}
void add(int cx, int cy, int l, int r, int d) {
    for(int i = l; i < r; i++) {
        int x = cx + dx[i];
        int y = cy + dy[i];
        A[y][x] += d;
    }
}

int hist_x[15];
int hist_y[15];
int hist_z[15];

bool dfs(int iter) {
    if(iter == N) {
        if(next().first != -1) return false;
        REP(i, N) {
            int x = hist_x[i];
            int y = hist_y[i];
            int z = hist_z[i];
            cout << x << " " << y << " " << z << endl;
        }
        return true;
    }

    auto p = next();
    int px = p.first, py = p.second;
    // REP(y, H) {
    //     REP(x, W) cout << A[y][x] << " ";
    //     cout << endl;
    // }
    REP(k, 3) for(int i = len[k]; i < len[k + 1]; i++) {
        int cx = px - dx[i];
        int cy = py - dy[i];
        int r = ok(cx, cy);

        int last = 0;
        for(int k2 = k; k2 < 3; k2++) {
            if(len[k2 + 1] <= r) {
                add(cx, cy, len[last], len[k2 + 1], -1);
                hist_x[iter] = cx;
                hist_y[iter] = cy;
                hist_z[iter] = k2 + 1;
                if(dfs(iter + 1)) return true;
                last = k2 + 1;
            } else {
                break;
            }
        }

        if(last > 0) {
            add(cx, cy, len[0], len[last], +1);
        }
    }

    return false;
}



int main(){
    while(cin >> N) {
        REP(y, H) REP(x, W) cin >> A[y][x];

        bool b = dfs(0);
        assert(b);
    }
    return 0;
}