#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP((i),0,(n))
#define RREP(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rrep(i,n) RREP(i,n,0)
#define each(it,X) for(__typeof((X).begin())  it=(X).begin();it!=(X).end();it++)
#define all(v) ((v).begin(),(v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int,int>pr;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef set<int>si;
const int INF=1070000000ll;
const int mod=1000000007ll;

int n,fld[20][20];
int p[3][5][5]={
    {{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,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 flag;
bool paint(int h,int w,int s){
    rep(i,5)rep(j,5){
        if(p[s][i][j]==0)continue;
        if(fld[h+i][w+j]==0)return false;
    }

    rep(i,5)rep(j,5){
        if(p[s][i][j]==0)continue;
        fld[h+i][w+j]--;
    }
    return true;
}
void repaint(int h,int w,int s){
    rep(i,5)rep(j,5){
        if(p[s][i][j])fld[h+i][w+j]++;
    }
}

void dfs(int h,int w,int cnt){
    if(h==10){
        if(cnt==0){
            flag=true;
        }
        return;
    }
    int th=(w==9?h+1:h),tw=(w+1)%10;
    rep(i,3){
        if(cnt<=0)break;
        if(paint(h,w,i)){
            dfs(h,w,cnt-1);
            if(flag){
                cout<<w+1+(i==2)<<" "<<h+1+(i==2)<<" "<<i+1<<endl;
                return;
            }
            repaint(h,w,i);
        }
    }

    if(fld[h][w])return;
    dfs(th,tw,cnt);
}
signed main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin>>n;
    rep(i,10)rep(j,10)cin>>fld[i][j];
    dfs(0,0,n);
    return 0;
}