#include <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

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

struct Solver {
  Solver(int n) : n(n) {}
  void setField(int F[10][10]){
    int s = 0;
    rep(i, 10){
      rep(j, 10){
        field[i][j] = F[i][j];
        s += F[i][j];
      }
    }
    sum = s;
  }
  bool isValid(int s, int m, int l){
    if (s + m + l != n) return false;
    if (5 * s + 9 * m + 13 * l != sum) return false;
    return true;
  }
  bool solve(int s, int m, int l){
    if (s + m + l == 0) return true;
    if (s != 0){
      reps(y, 1, 9){
        reps(x, 1, 9){
          bool ok = push(x, y, 4);
          if (ok) {
            bool complete = solve(s - 1, m, l);
            if (complete){
              printf("%d %d 1\n", x, y);
              return true;
            }
          }
          pop(x, y, 4);
        }
      }
      return false;
    }
    if (m != 0){
      reps(y, 1, 9){
        reps(x, 1, 9){
          bool ok = push(x, y, 8);
          if (ok) {
            bool complete = solve(s, m - 1, l);
            if (complete){
              printf("%d %d 2\n", x, y);
              return true;
            }
          }
          pop(x, y, 8);
        }
      }
      return false;
    }
    if (l != 0){
      reps(y, 2, 8){
        reps(x, 2, 8){
          bool ok = push(x, y, 12);
          if (ok) {
            bool complete = solve(s, m, l - 1);
            if (complete){
              printf("%d %d 3\n", x, y);
              return true;
            }
          }
          pop(x, y, 12);
        }
      }
      return false;
    }
    return false;
  }
  bool push(int x, int y, int len){
    bool ok = true;
    rep(i, len){
      int nx, ny;
      nx = x + dx[i];
      ny = y + dy[i];
      --field[ny][nx];
      if (field[ny][nx] < 0) ok = false;
    }
    return ok;
  }
  void pop(int x, int y, int len){
    rep(i, len){
      int nx, ny;
      nx = x + dx[i];
      ny = y + dy[i];
      ++field[ny][nx];
    }
  }
  int field[10][10];
  int sum;
  int n;
};

int main()
{
  int n = in();
  int f[10][10];
  rep(i, 10){
    rep(j, 10){
      f[i][j] = in();
    }
  }
  Solver s(n);
  s.setField(f);
  rep(i, n + 1){
    rep(j, n + 1){
      rep(k, n + 1){
        if (s.isValid(i, j, k)){
          bool ok = s.solve(i, j, k);
          if (ok){
            return (0);
          }
        }
      }
    }
  }
  return (1);
}