#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

int dy[][5] = {{0, 1, 0, -1, 0}, {1,  1, -1, -1, 0}, {-2, 0, 2,  0, 0}};
int dx[][5] = {{0, 0, 1, 0, -1}, {1, -1,  1, -1, 0}, { 0, 2, 0, -2, 0}};

int dye[10][10];


void dump()
{
    rep(i, 10){
        rep(j, 10) cout << dye[i][j];
        cout << endl;
    }
}

bool puttable(int y, int x, int s)
{
    rep(i, s){
        rep(j, 5){
            int py = y + dy[i][j];
            int px = x + dx[i][j];
            if(dye[py][px] == 0) return false;
        }
    }
    
    return true;
}

void put(int y, int x, int s, bool minus)
{
    rep(i, s){
        rep(j, 5){
            int py = y + dy[i][j];
            int px = x + dx[i][j];
            dye[py][px] += minus ? -1 : 1;
        }
    }
}

bool search(int num[])
{
    rep(i, 3){
        if(num[i] > 0){
            num[i]--;
            int s = 3 - i;
            int o = s == 3 ? 2 : 1;
            reps(y, o, 10-o){
                reps(x, o, 10-o){
                    if(puttable(y, x, s)){
                        put(y, x, s, true);
                        if(search(num)){
                            cout << x << ' ' << y << ' ' << s << endl;
                            return true;
                        }
                        put(y, x, s, false);
                    }
                }
            }
            num[i]++;
            return false;
        }
    }
    
    return true;
}

int main()
{
    int n;
    cin >> n;
    
    int a = 0;
    rep(i, 10) rep(j, 10){
        cin >> dye[i][j];
        a += dye[i][j];
    }
    
    int m = (a - n) / 4;
    for(int x=0;; ++x){
        int y = -a + 5*m - 2*x;
        int z = 2*a - 9*m + x;
        int num[] = {x, y, z};
        if(search(num)){
            break;
        }
        
        if(y<0 || z<0) break;
    }
}