#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}
int in[10][10];

int a[3][5][5] = {
    /*Small*/
  {{ 0, 0, 1, 0, 0},
   { 0, 1, 1, 1, 0},
   { 0, 0, 1, 0, 0}},
  //*midium*/
  {{ 0, 0, 1, 1, 1},
   { 0, 0, 1, 1, 1},
   { 0, 0, 1, 1, 1}},
  /*large*/
  {{ 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){
    rep(i,5)rep(j,5){
        int p = x+i, q = y+j-2;
        if(p < 0 || p > 9 || q < 0 || q > 9){
            if(a[t][i][j])return false;
        }else if(in[p][q] - a[t][i][j] < 0)return false;
    }
    return true;
}

void paint(int x, int y, int t){
    rep(i,5)rep(j,5)in[x+i][y+j-2] -= a[t][i][j];
}
void repaint(int x, int y, int t){
    rep(i,5)rep(j,5)in[x+i][y+j-2] += a[t][i][j];
}

bool f(int x, int y, int n){
    if(n < 0)return false;
    if(x == 10)return n == 0;
    if(in[x][y] == 0)return f(x+(y == 9), (y+1)%10, n);
    rep(i,3){
        if(check(x,y,i) == false)continue;
        paint(x,y,i);
        if(f(x,y,n-1)){
            if(i == 0)cout << y << " " << x+1;
            if(i == 1)cout << y+1 << " " << x+1;
            if(i == 2)cout << y << " " << x+2;
            cout << " " << i+1 << endl;
            return true;
        }
        repaint(x,y,i);
    }
    return false;
}

signed main(void) {
    int n;
    cin >> n;
    rep(i,10)rep(j,10)cin >> in[i][j];
    f(0,0,n);
}

