#include <cstdio>

int N, map[10][10];
int x[12], y[12], bl[12];
int bls[3][5][5] = {{{0,0,0,0,0},{0,0,1,0,0},{0,1,1,1,0},{0,0,1,0,0},{0,0,0,0,0}},
                    {{0,0,0,0,0},{0,1,1,1,0},{0,1,1,1,0},{0,1,1,1,0},{0,0,0,0,0}},
                    {{0,0,1,0,0},{0,1,1,1,0},{1,1,1,1,1},{0,1,1,1,0},{0,0,1,0,0}}};

bool check(int x, int y, int t){
    int tmp, u = 0;
    if(t <= 1) u = 1;
    for(int i = -2 + u; i <= 2 - u; i++){
        for(int j = -2 + u; j <= 2 - u; j++){
            if(x + i >= 10 || y + j >= 10 || x + i < 0 || y + j < 0) continue;
            tmp = map[x + i][y + j] + bls[t][i + 2][j + 2] * (-1);

            if(tmp < 0) return false;
        }
    }
    return true;
}

void ss(int x, int y, int t, int v){
    //v???-????????????????????????+?????????????????????
    int u = 0;
    if(t <= 1) u = 1;
    for(int i = -2 + u; i <= 2 - u; i++){
        for(int j = -2 + u; j <= 2 - u; j++){
            if(x + i >= 10 || y + j >= 10 || x + i < 0 || y + j < 0) continue;
            map[x + i][y + j] += bls[t][i + 2][j + 2] * v;
        }
    }
}

bool solve(int n){
    if(n == N){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                if(map[i][j]) return false;
            }
        }

        for(int i = 0; i < N; i++){
            printf("%d %d %d\n", x[i], y[i], bl[i]);
        }
        return true;
    }

    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            if(!map[i][j]) continue;

            for(int k = 0; k < 3; k++){
                if(!check(i, j, k)) continue;
                ss(i, j, k, -1); //???????????????

                x[n] = j; y[n] = i; bl[n] = k + 1;
                if(solve(n + 1)) return true;
                ss(i, j, k, 1); //???????????????
            }
        }
    }

    return false;
}

int main(){
    scanf("%d", &N);
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            scanf("%d", &map[i][j]);
        }
    }

    solve(0);


    return 0;
}