#include <iostream>
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

int g[10][10];
int n;
int ansx[12];
int ansy[12];
int anss[12];
int valid[13][256];

bool canPut(int y, int x, int sz){
  const int sizes[] = {1, 1, 2};
  const int s = sizes[sz];
  if(ISIN(x - s, y - s, 10, 10) &&
     ISIN(x + s, y + s, 10, 10)){
    if(g[x    ][y    ] == 0 ||
       g[x - 1][y    ] == 0 ||
       g[x    ][y - 1] == 0 ||
       g[x + 1][y    ] == 0 ||
       g[x    ][y + 1] == 0)
      return false;

    if(sz >= 1){
      if(g[x - 1][y - 1] == 0 ||
         g[x - 1][y + 1] == 0 ||
         g[x + 1][y - 1] == 0 ||
         g[x + 1][y + 1] == 0)
        return false;
    }

    if(sz >= 2){
      if(g[x - 2][y    ] == 0 ||
         g[x    ][y - 2] == 0 ||
         g[x + 2][y    ] == 0 ||
         g[x    ][y + 2] == 0)
        return false;
    }

    return true;
  }else{
    return false;
  }
}

void put(int y, int x, int sz){
  g[x    ][y    ]--;
  g[x - 1][y    ]--;
  g[x    ][y - 1]--;
  g[x + 1][y    ]--;
  g[x    ][y + 1]--;

  if(sz >= 1){
    g[x - 1][y - 1]--;
    g[x - 1][y + 1]--;
    g[x + 1][y - 1]--;
    g[x + 1][y + 1]--;
  }

  if(sz >= 2){
    g[x - 2][y    ]--;
    g[x    ][y - 2]--;
    g[x + 2][y    ]--;
    g[x    ][y + 2]--;
  }
}

void unput(int y, int x, int sz){
  g[x    ][y    ]++;
  g[x - 1][y    ]++;
  g[x    ][y - 1]++;
  g[x + 1][y    ]++;
  g[x    ][y + 1]++;

  if(sz >= 1){
    g[x - 1][y - 1]++;
    g[x - 1][y + 1]++;
    g[x + 1][y - 1]++;
    g[x + 1][y + 1]++;
  }

  if(sz >= 2){
    g[x - 2][y    ]++;
    g[x    ][y - 2]++;
    g[x + 2][y    ]++;
    g[x    ][y + 2]++;
  }
}

void calcCand(int cand[10][10]){
  REP(i,10) REP(j,10){
    cand[i][j] = 0;
    REP(k,3) if(canPut(i, j, k))
      cand[i][j] |= (1 << k);
  }
}

bool isValid(int cand[10][10]){
  bool ret = true;

  REP(i,10) REP(j,10) REP(k,3)
    if(cand[i][j] & (1 << k))
      put(i, j, k);

  REP(i,10) REP(j,10)
    if(g[i][j] > 0) ret = false;

  REP(i,10) REP(j,10) REP(k,3)
    if(cand[i][j] & (1 << k))
      unput(i, j, k);

  return ret;
}

int cnts[3] = { 5, 9, 13 };

void solve(int n, int cnt){
  if(n == 0 && cnt == 0){
    REP(i,::n)
      printf("%d %d %d\n", ansx[i], ansy[i], anss[i]);
    throw 0;
  }
  if(!valid[n][cnt])
    return;

  int cand[10][10] = {{ 0 }};
  calcCand(cand);

  // REP(i,10){ REP(j,10) printf("%d ", cand[i][j]); puts(""); }

  REP(i,10) REP(j,10) REP(k,3)
    if(cand[i][j] & (1 << k)){
      if(cnt >= cnts[k] && valid[n - 1][cnt - cnts[k]]){
        put(i, j, k);
        ansx[::n - n] = j;
        ansy[::n - n] = i;
        anss[::n - n] = k + 1;
        solve(n - 1, cnt - cnts[k]);
        unput(i, j, k);
      }
    }
}

int main(){
  int cnt = 0;
  n = getInt();
  REP(i,10) REP(j,10)
    cnt += (g[i][j] = getInt());

  valid[0][0] = 1;
  REP(i,n) REP(j,256) if(valid[i][j]){
    valid[i + 1][j + 5] =
      valid[i + 1][j + 9] =
      valid[i + 1][j + 13] = 1;
  }

  try{
    solve(n, cnt);
  }catch(int e){
    (void)e;
  }

  return 0;
}