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

int q, mas[10][10], dy[] = {1, 1, 2}, dx[] = {0, 1, 0};
int draw[][5][5] = {
    {{0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}},
    {{0, 0, 1, 1, 1}, {0, 0, 1, 1, 1}, {0, 0, 1, 1, 1}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}},
    {{0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {1, 1, 1, 1, 1}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}},
};

bool check(int y, int x, int w) {
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      if (mas[y + i][x + j - 2] - draw[w][i][j] < 0) return false;
    }
  }
  return true;
}

void paint(int y, int x, int w) {
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      mas[y + i][x + j - 2] -= draw[w][i][j];
    }
  }
}

void repaint(int y, int x, int w) {
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      mas[y + i][x + j - 2] += draw[w][i][j];
    }
  }
}

bool dfs(int y = 0, int x = 0, int n = q) {
  if (n < 0) return false;
  if (y == 10) return n == 0;
  if (mas[y][x] == 0) return dfs(y + (x == 9), (x + 1) % 10, n);
  for (int i = 0; i < 3; i++) {
    if (!check(y, x, i)) continue;
    paint(y, x, i);
    if (dfs(y, x, n - 1)) {
      cout << x + (i == 1) << " " << y + 1 + (i == 2) << " " << i + 1 << endl;
      return true;
    }
    repaint(y, x, i);
  }
  return false;
}

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

  dfs();
}