#include<iostream>
#include<cmath>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int n;
int a[10][10];
int res[3][12][2];
int ii, jj, kk;

bool solve(int i, int j, int k, int y, int x) {
  if (y == 10) {
    if (i == 0 && j == 0 && k == 0) {
      rep (t, ii) cout << res[0][t][1] << " " << res[0][t][0] << " 3" << endl;
      rep (t, jj) cout << res[1][t][1] << " " << res[1][t][0] << " 2" << endl;
      rep (t, kk) cout << res[2][t][1] << " " << res[2][t][0] << " 1" << endl;
      return true;
    } else {
      return false;
    }
  }
  if (x == 10) return solve(i, j, k, y + 1, 0);
  if (a[y][x] == 0) return solve(i, j, k, y, x + 1);
  if (solve(i, j, k, y, x + 1)) return true;
  bool flag;
  if (i > 0 && 2 <= y && y < 8 && 2 <= x && x < 8) {
    flag = true;
    res[0][i - 1][0] = y;
    res[0][i - 1][1] = x;
    for (int t = -2; t <= 2; ++t) for (int s = -2; s <= 2; ++s) {
	if (abs(t) + abs(s) <= 2) {
	  --a[y + t][x + s];
	  if (a[y + t][x + s] < 0) flag = false;
	}
      }
    if (flag) {
      if (solve(i - 1, j, k, y, x + 1)) return true;
    }
    for (int t = -2; t <= 2; ++t) for (int s = -2; s <= 2; ++s) {
	if (abs(t) + abs(s) <= 2) {
	  ++a[y + t][x + s];
	}
      }
  }
  if (j > 0 && 1 <= y && y < 9 && 1 <= x && x < 9) {
    flag = true;
    res[1][j - 1][0] = y;
    res[1][j - 1][1] = x;
    for (int t = -1; t <= 1; ++t) for (int s = -1; s <= 1; ++s) {
	--a[y + t][x + s];
	if (a[y + t][x + s] < 0) flag = false;
      }
    if (flag) {
      if (solve(i, j - 1, k, y, x + 1)) return true;
    }
    for (int t = -1; t <= 1; ++t) for (int s = -1; s <= 1; ++s) {
	++a[y + t][x + s];
      }
  }
  if (k > 0 && 1 <= y && y < 9 && 1 <= x && x < 9) {
    flag = true;
    res[2][k - 1][0] = y;
    res[2][k - 1][1] = x;
    for (int t = -1; t <= 1; ++t) for (int s = -1; s <= 1; ++s) {
	if (abs(t) + abs(s) <= 1) {
	  --a[y + t][x + s];
	  if (a[y + t][x + s] < 0) flag = false;
	}
      }
    if (flag) {
      if (solve(i, j, k - 1, y, x + 1)) return true;
    }
    for (int t = -1; t <= 1; ++t) for (int s = -1; s <= 1; ++s) {
	if (abs(t) + abs(s) <= 1) {
	  ++a[y + t][x + s];
	}
      }
  }
  return false;
}

int main() {
  cin >> n;
  rep (i, 10) rep (j, 10) cin >> a[i][j];
  int cnt = 0;
  rep (i, 10) rep (j, 10) cnt += a[i][j];
  rep (i, n + 1) rep (j, n + 1) rep (k, n + 1) {
    if (i + j + k != n) continue;
    if (i * 13 + j * 9 + k * 5 != cnt) continue;
    ii = i;
    jj = j;
    kk = k;
    if (solve(i, j, k, 0, 0)) return 0;
  }
}