#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];
int movex[] = {1, 1, 2}, movey[] = {0, 1, 0};
struct Elem {
    int x, y, blur;
};

bool answerFlag = false;

void solve(vector< vector<int> > &board, vector<Elem> &rec, int restcnt, int restblur) {
    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;
        exit(0);
    }
    if(restcnt == 0) return;
    rep(i,0,10) rep(j,0,10) {
        if(board[i][j] != 0) {
            rep(k,0,3) {
                int nx = i + movex[k], ny = j + movey[k];
                if(nx < 0 || nx >= 10 || ny < 0 || ny >= 10) continue;

                bool ok = true;
                rep(x,0,patx[k].size()) {
                    int sx = nx + patx[k][x], sy = ny + paty[k][x];
                    if(sx < 0 || sx >= 10 || sy < 0 || sy >= 10 || !board[sx][sy]) ok = false;
                }

                if(ok) {
                    rep(x,0,patx[k].size()) {
                        int sx = nx + patx[k][x], sy = ny + paty[k][x];
                        board[sx][sy]--;
                    }
                    rec.push_back(Elem{ny, nx, k+1});

                    solve(board, rec, restcnt-1, restblur-patx[k].size());

                    rep(x,0,patx[k].size()) {
                        int sx = nx + patx[k][x], sy = ny + paty[k][x];
                        board[sx][sy]++;
                    }
                    rec.pop_back();
                }
            }
            return;
        }
    }
}

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

    paty[0] = {0, 0, 1, -1, 0};
    paty[1] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
    paty[2] = {-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);
}

Measured memory_bytes: 3260