#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

struct po{int y,x,type;};
bool operator==(const po &a, const po &b){
  return a.y==b.y && a.x==b.x && a.type==b.type;
}

vector<po> dfs(int rest, vector<vi> mp, int y, int x){
  vector<po> err(1);
  err[0] = (po){-1,-1,-1};
  if(rest==0){
    // check it is ok
    bool flag = true;
    // REP(i,10){
    //   REP(j,10)printf("%04d ",mp[i][j]);
    //   cout<<endl;
    // }
    // cout<<endl;
    REP(i,10)REP(j,10){
      if(mp[i][j]!=0)flag=false;
    }
    if(flag){
      return vector<po>();
    }else{
      return err;
    }
  }else{
    while(true){
      if(y>9)return err;
      if(mp[y][x]>0){
        vector<vi> nmp;
        if(y<=7 && x>0 && x<9){
          // ?°?
          nmp = mp;
          REP(o,3)REP(p,3)if(abs(o-1)+abs(p-1)<=1)nmp[y+o][x-1+p]--;
          vector<po> s = dfs(rest-1,nmp,y,x);
          if(s!=err){
            s.push_back((po){y+1,x,1});
            return s;
          }
        }
        if(y<=7 && x<=7){
          // ??¨
          nmp = mp;
          REP(o,3)REP(p,3)nmp[y+o][x+p]--;
          vector<po> s = dfs(rest-1,nmp,y,x);
          if(s!=err){
            s.push_back((po){y+1,x+1,2});
            return s;
          }
        }
        if(y<=5 && x>=2 && x<=7){
          // ??§
          nmp = mp;
          REP(o,5)REP(p,5)if(abs(o-2)+abs(p-2)<=2)nmp[y+o][x-2+p]--;
          vector<po> s = dfs(rest-1,nmp,y,x);
          if(s!=err){
            s.push_back((po){y+2,x,3});
            return s;
          }
        }
        return err;
      }
      ++x;
      if(x>9){
        x=0;
        ++y;
      }
    }
  }
}

int main(){
  int n;
  cin>>n;
  vector<vi> mp(10,vi(10));
  REP(i,10)REP(j,10)cin>>mp[i][j];
  vector<po> res = dfs(n,mp,0,0);
  REP(i,res.size()){
    cout<< res[i].x << " " << res[i].y << " " << res[i].type << endl;
  }
  return 0;
}