#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n;
vector<vector<int>> a(10, vector<int>(10));
vector<vector<vector<int>>> drop = {
  {{0, 1, 0},
   {1, 1, 1},
   {0, 1, 0}},
  {{1, 1, 1},
   {1, 1, 1},
   {1, 1, 1}},
  {{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}}
};
int dz[3] = {3, 3, 5};

bool can_paint(int y, int x, int mode) {
  int len = drop[mode].size();
  if (max(y, x) + len > 10) return false;
  for (int i = 0; i < len; i++) {
    for (int j = 0; j < len; j++) {
      if (a[y + i][x + j] - drop[mode][i][j] < 0) return false;
    }
  }
  return true;
}

void paint(int y, int x, int mode) {
  for (int i = 0; i < dz[mode]; i++) {
    for (int j = 0; j < dz[mode]; j++) {
      a[y + i][x + j] -= drop[mode][i][j];
    }
  }
}

void undo(int y, int x, int mode) {
  for (int i = 0; i < dz[mode]; i++) {
    for (int j = 0; j < dz[mode]; j++) {
      a[y + i][x + j] += drop[mode][i][j];
    }
  }
}

bool rec(int y, int x, int rem) {
  if (rem < 0) return false;
  if (y == 10) return rem == 0;
  for (int i = 0; i < 3; i++) {
    if (!can_paint(y, x, i)) continue;
    paint(y, x, i);
    if (rec(y, x, rem - 1)) {
      cout << x + dz[i] / 2 << " " << y + dz[i] / 2 << " " << i + 1 << endl;
      return true;
    }
    undo(y, x, i);
  }
  if (a[y][x]) return false;
  if (rec(y + (x == 9), (x + 1) % 10, rem)) return true;
  return false;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> n;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> a[i][j];
    }
  }
  rec(0, 0, n);

  return 0;
}
