#include <bits/stdc++.h>
using namespace std;

int n;
int b[10][10];

bool inside(int y, int x) {
  return 0 <= y && y < 10 && 0 <= x && x < 10;
}

inline bool latte(int y, int x, int type, int d = 0) {
  int dx[13] = {0, 0, 1, 0, -1, -1, 1, 1, -1, 0, 2, 0, -2};
  int dy[13] = {0, -1, 0, 1, 0, -1, -1, 1, 1, -2, 0, 2, 0};

  if (d == -1) {
    for (int i = 0; i <= 4 * type; ++i) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (!b[ny][nx] || !inside(ny, nx)) return false;
    }
  }

  for (int i = 0; i <= 4 * type; ++i) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    b[ny][nx] += d;
  }

  return true;
}

inline bool dfs(int v = 0, int y = 1, int x = 1) {
  if (y == 9) return false;

  if (v == n) {
    // debug();
    for (int i = 0; i < 10; ++i) {
      for (int j = 0; j < 10; ++j) {
        if (b[i][j]) return false;
      }
    }
    return true;
  }

  int nx = x % 8 + 1;
  int ny = y + (nx == 1);
  if (!b[y][x]) return dfs(v, ny, nx);

  for (int i = 3; i > 0; --i) {
    if (latte(y, x, i, -1)) {
      if (dfs(v + 1, y, x)) {
        printf("%d %d %d\n", x, y, i);
        return true;
      }
      latte(y, x, i, 1);
    }
  }

  return dfs(v, ny, nx);
}

int main() {
  cin >> n;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> b[i][j];
    }
  }

  dfs();
  // debug();
}