#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int H = 10;
const int W = 10;

int ans[H][W], v[H][W];
bool f;

int l[3] = {5, 9, 13};
int my[3][13] = {{-1, 0, 0, 0, 1}, {-1, -1, -1, 0, 0, 0, 1, 1, 1}, {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2}};
int mx[3][13] = {{0, -1, 0, 1, 0}, {-1, 0, 1, -1, 0, 1, -1, 0, 1}, {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}};

bool isEnd(){
  REP(i, H) REP(j, W) if(v[i][j]) return false;
  return true;
}

bool canDrop(int y, int x, int m){
  REP(i, l[m]){
    int ny = y + my[m][i], nx = x + mx[m][i];
    if(ny < 0 || nx < 0 || ny >= H || nx >= W || v[ny][nx] <= 0) return false;
  }
  return true;
}

void drop(int y, int x, int m, int p){
  REP(i, l[m]){
    int ny = y + my[m][i], nx = x + mx[m][i];
    v[ny][nx] += p;
  }
}

void dfs(int n){
  if(n == 0 && isEnd()){ f = true; return ; }
  REP(i, H){
    REP(j, H){
      for(int k = 2; k >= 0; --k){
        if(canDrop(i, j, k)){
          drop(i, j, k, -1); ans[i][j] = k + 1;
          dfs(n - 1);
          if(f) return ;
          drop(i, j, k, 1); ans[i][j] = 0; 
        }
      }
    }
  }
}

int main() {
  int N; cin >>N;
  memset(ans, 0, sizeof(ans));
  REP(i, H) REP(j, H) cin >>v[i][j];
  dfs(N);
  if(f) REP(i, H) REP(j, W) if(ans[i][j]) cout <<j <<" " <<i <<" " <<ans[i][j] <<endl;
  return 0;
}