#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
typedef tuple<int, int, int> tri;
const int dx[] = {0, 0, 0, 1, -1, 1, 1, -1, -1, -2, 2, 0, 0};
const int dy[] = {0, 1, -1, 0, 0, 1, -1, 1, -1, 0, 0, -2, 2};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

struct Solver {
  const int N;
  int F[10][10];
  int S[10][10], M[10][10], L[10][10];
  int cnt;
  vector<tri> ans;
  Solver(int n) : N(n) {}
  void read(){
    cnt = 0;
    for (int i = 0; i < 10; i++){
      for (int j = 0; j < 10; j++){
        F[i][j] = in();
        cnt += F[i][j];
      }
    }
    memset(S, 0, sizeof(S));
    memset(M, 0, sizeof(M));
    memset(L, 0, sizeof(L));
    for (int i = 1; i < 9; i++){
      for (int j = 1; j < 9; j++){
        S[i][j] = M[i][j] = 255;
        for (int d = 0; d < 5; d++){
          S[i][j] = min(S[i][j], F[i + dy[d]][j + dx[d]]);
        }
        for (int d = 0; d < 9; d++){
          M[i][j] = min(M[i][j], F[i + dy[d]][j + dx[d]]);
        }
      }
    }
    for (int i = 2; i < 8; i++){
      for (int j = 2; j < 8; j++){
        L[i][j] = 255;
        for (int d = 0; d < 13; d++){
          L[i][j] = min(L[i][j], F[i + dy[d]][j + dx[d]]);
        }
      }
    }
  }
  void solve(){
    for (int s = 10; s >= 0; s--){
      for (int m = 10; m >= 0; m--){
        int l = N - s - m;
        if (s * 5 + m * 9 + l * 13 != cnt) continue;
        if (dfs(s, m, l)) return;
      }
    }
  }
  bool dfs(int s, int m, int l){
    if (!(s || m || l)) return true;
    if (s){
      for (int i = 0; i < 9; i++){
        for (int j = 0; j < 9; j++){
          if (!S[i][j]) continue;
          if (!push(i, j, 0)){
            pop(i, j, 0);
            continue;
          }
          bool ok = dfs(s - 1, m, l);
          if (ok) return true;
          pop(i, j, 0);
        }
      }
    }
    if (m){
      for (int i = 0; i < 9; i++){
        for (int j = 0; j < 9; j++){
          if (!M[i][j]) continue;
          if (!push(i, j, 1)){
            pop(i, j, 1);
            continue;
          }
          bool ok = dfs(s, m - 1, l);
          if (ok) return true;
          pop(i, j, 1);
        }
      }
    }
    if (l){
      for (int i = 0; i < 9; i++){
        for (int j = 0; j < 9; j++){
          if (!L[i][j]) continue;
          if (!push(i, j, 2)){
            pop(i, j, 2);
            continue;
          }
          bool ok = dfs(s, m, l - 1);
          if (ok) return true;
          pop(i, j, 2);
        }
      }
    }
    return false;
  }
  bool push(int y, int x, int t){
    static const int len[] = {5, 9, 13};
    if (t == 0) S[y][x]--;
    else if (t == 1) M[y][x]--;
    else L[y][x]--;
    bool ok = true;
    for (int d = 0, l = len[t]; d < l; d++){
      int& a = F[y + dy[d]][x + dx[d]];
      a--;
      if (a < 0) ok = false;
    }
    ans.emplace_back(x, y, t + 1);
    return ok;
  }
  void pop(int y, int x, int t){
    static const int len[] = {5, 9, 13};
    if (t == 0) S[y][x]++;
    else if (t == 1) M[y][x]++;
    else L[y][x]++;
    for (int d = 0, l = len[t]; d < l; d++){
      int& a = F[y + dy[d]][x + dx[d]];
      a++;
    }
    ans.pop_back();
  }
  vector<tri> get_ans(){ return ans; }
};

int main()
{
  int n = in();
  Solver sol(n);
  sol.read();
  sol.solve();
  auto x = sol.get_ans();
  show(x, [](tri a){cout<<get<0>(a)<<" "<<get<1>(a)<<" "<<get<2>(a);}, "\n");
  return 0;
}