#include <iostream>
#include <algorithm>
using namespace std;

const int H = 10;
const int W = 10;
const int MAXN = 20;

int N;
int G[H][W];
int X[MAXN], Y[MAXN], S[MAXN];

int draw(int x, int y, int s, int c) {
  const static int num[3] = {5, 9, 13};
  const static int dx[13] = {0,1,0,-1,0,1,-1,-1,1,2,0,-2,0};
  const static int dy[13] = {0,0,1,0,-1,1,1,-1,-1,0,2,0,-2};
  int res = 0;
  bool flag = false;
  for(int i = 0; i < num[s]; ++i) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx < 0 || nx >= W || ny < 0 || ny >= H) {
      flag = true;
      continue;
    }
    G[ny][nx] += c;
    if(G[ny][nx] < 0) flag = true;
    ++res;
  }
  if(flag) return 0;
  else return res;
}

bool rec(int n, int sum) {
  if(sum < 0) return false;
  if(n == N) {
    if(sum != 0) return false;
    for(int i = 0; i < N; ++i) {
      cout << X[i] << " " << Y[i] << " " << S[i]+1 << endl;
    }
    return true;
  }

  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      if(G[i][j] == 0) continue;
      for(int s = 0; s < 3; ++s) {
        int tmp = draw(j,i,s,-1);
        if(tmp) {
          X[n] = j;
          Y[n] = i;
          S[n] = s;
          if(rec(n+1, sum-tmp)) return true;
        }
        draw(j,i,s,1);
      }
    }
  }
  return false;
}

int main() {
  cin >> N;
  int sum = 0;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      cin >> G[i][j];
      sum += G[i][j];
    }
  }
  rec(0, sum);
  return 0;
}