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

int dx[3][4] = {{0, 1, 0, -1}, {-1, 1, 1, -1}, {0, 2, 0, -2}};
int dy[3][4] = {{-1, 0, 1, 0}, {-1, -1, 1, 1}, {-2, 0, 2, 0}};

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

int ans_x[12], ans_y[12], ans[12];

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

bool dfs(int i = 0, int y = 1, int x = 1) {
  if (y == 10) return false;
  if (i == n) {
    bool f = true;
    for (int j = 0; j < 10; ++j) {
      for (int k = 0; k < 10; ++k) {
        if (b[j][k]) f = false;
      }
    }
    if (f) {
      for (int j = 0; j < n; ++j) {
        cout << ans_x[j] << " " << ans_y[j] << " " << ans[j] << endl;
      }
      return true;
    }

    return false;
  }

  int ny = y + (x == 9);
  int nx = (x + 1) % 10;

  if (b[y][x]) {
    b[y][x] = false;
    for (int k = 0; k < 3; ++k) {
      bool f = false;
      for (int l = 0; l < 4; ++l) {
        int nny = y + dy[k][l];
        int nnx = x + dx[k][l];
        if (!inside(nny, nnx) || !b[nny][nnx]) f = true;
      }
      if (f) {
        for (int j = 0; j < k; ++j) {
          for (int l = 0; l < 4; ++l) {
            int nny = y + dy[j][l];
            int nnx = x + dx[j][l];
            b[nny][nnx] = true;
          }
        }
        break;
      } else {
        for (int l = 0; l < 4; ++l) {
          int nny = y + dy[k][l];
          int nnx = x + dx[k][l];
          b[nny][nnx] = false;
        }
        ans_y[i] = y;
        ans_x[i] = x;
        ans[i] = k + 1;
        if (dfs(i + 1, y, x)) true;
      }
    }
    b[y][x] = true;
  }

  return dfs(i, 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();
}