#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 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 const MOD = 1000000007;

vector<int> patx[3], paty[3];
struct Elem {
    int x, y, blur;
};

bool answerFlag = false;

void solve(vector< vector<int> > &board, vector<Elem> &rec, int restcnt, int restblur, int lastp=0) {
    if(answerFlag) return;
    if(restcnt * 5 > restblur) return;
    if(restcnt == 0 && restblur == 0) {
        rep(i,0,rec.size()) {
            printf("%d %d %d\n", rec[i].x, rec[i].y, rec[i].blur);
        }
        answerFlag = true;
        return;
    }
    if(restcnt == 0) return;
    rep(i,0,10) rep(j,0,10) {
        if(10*i+j < lastp) continue;
        if(board[i][j] != 0) {
            rep(k,0,3) {
                if(restblur - (int)patx[k].size() < 0) continue;
                bool ok = true;
                rep(l,0,patx[k].size()) {
                    int x = i + patx[k][l], y = j + paty[k][l];
                    if(x < 0 || x >= 10 || y < 0 || y >= 10 || board[x][y] == 0) ok = false;
                }
                if(ok) {
                    rep(l,0,patx[k].size()) {
                        int x = i + patx[k][l], y = j + paty[k][l];
                        board[x][y]--;
                    }
                    rec.push_back(Elem{j, i, k+1});

                    solve(board, rec, restcnt-1, restblur - (int)patx[k].size(), 10*i+j);

                    rep(l,0,patx[k].size()) {
                        int x = i + patx[k][l], y = j + paty[k][l];
                        board[x][y]++;
                    }
                    rec.pop_back();
                }
            }
        }
    }
}

signed main() {
    patx[2] = {1, -1, 0, 0, 0};
    patx[1] = {0, -1, 1, 0, -1, 1, 0, -1, 1};
    patx[0] = { 0,  0, 0, 0, 0, -2, -1, 1, 2, 1, 1, -1, -1};

    paty[2] = {0, 0, 1, -1, 0};
    paty[1] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
    paty[0] = {-2, -1, 0, 1, 2,  0,  0, 0, 0, 1, -1, 1, -1};
    int n; cin >> n;
    vector< vector<int> > v(10, vector<int>(10, 0));
    int blurcnt = 0;
    rep(i,0,10) rep(j,0,10) {
        cin >> v[i][j];
        blurcnt += v[i][j];
    }
    vector<Elem> init;
    solve(v, init, n, blurcnt);
}