#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct Drop { int x, y, siz; };
vector<Drop> v, ans;

vector<vector<int>> dx = {
    {},
    {0, -1, 0, 1, 0},
    {0, 1, 2, 0, 1, 2, 0, 1, 2},
    {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}
};
vector<vector<int>> dy = {
    {},
    {0, 1, 1, 1, 2},
    {0, 0, 0, 1, 1, 1, 2, 2, 2},
    {0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4}
};

vector<int> pos_x = {0, 0, 1, 0};
vector<int> pos_y = {0, 1, 1, 2};

int n;
int cloth[20][20];

pair<int,int> findBlur() {
    for (int i=5; i<15; ++i) {
        for (int j=5; j<15; ++j) {
            if (0 < cloth[i][j]) {
                return make_pair(j, i);
            }
        }
    }
    return make_pair(-1, -1);
}

void solve() {
    int x, y;
    pair<int,int> t = findBlur();
    if (t.first < 0) {
        if ((int)v.size() == n) {
            ans = v;
        }
        return ;
    } else {
        x = t.first;
        y = t.second;
    }
    for (int i=1; i<=3; ++i) {
        int n = dx[i].size();
        bool ok = true;
        for (int j=0; j<n; ++j) {
            if (cloth[y + dy[i][j]][x + dx[i][j]] <= 0) {
                ok = false;
                break;
            }
        }
        if (ok) {
            for (int j=0; j<n; ++j) {
                cloth[y + dy[i][j]][x + dx[i][j]] --;
            }
            v.push_back((Drop){ x + pos_x[i] - 5, y + pos_y[i] - 5, i });
            solve();
            v.pop_back();
            for (int j=0; j<n; ++j) {
                cloth[y + dy[i][j]][x + dx[i][j]] ++;
            }
        }
    }
}

int main() {
    cin >> n;
    for (int i=5; i<15; ++i) {
        for (int j=5; j<15; ++j) {
            cin >> cloth[i][j];
        }
    }
    solve();
    for (int i=0; i<(int)ans.size(); ++i) {
        cout << ans[i].x << " " << ans[i].y << " " << ans[i].siz << endl;
    }
    return 0;
}