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

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

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

void cord(int y, int x, string s = "\n") {
  printf("(%d, %d)", y, x);
  cout << s;
}

void debug(int x = -1) {
  puts("");
  if (~x) cout << x << endl;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cout << b[i][j] << " ";
    }
    cout << endl;
  }
  for (int i = 0; i < n; ++i) {
    printf("%d %d %d\n", ans_x[i], ans_y[i], ans_type[i]);
  }
}

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

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;
}

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

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

    for (int i = 0; i < n; ++i) {
      printf("%d %d %d\n", ans_x[i], ans_y[i], ans_type[i]);
    }
    return true;
  }

  for (int i = 1; i <= 3; ++i) {
    if (latte(y, x, i, -1)) {
      ans_y[v] = y;
      ans_x[v] = x;
      ans_type[v] = i;
      if (dfs(v + 1, y, x)) return true;
      latte(y, x, i, 1);
    }
  }

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

  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();
}