#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int H = 10;
const int W = 10;

bool f;
vector<PP> ans;
vector< vector<int> > tar;

int N, l[3] = {5, 9, 13};
int my[3][13] = {{-1, 0, 0, 0, 1}, {-1, -1, -1, 0, 0, 0, 1, 1, 1}, {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2}};
int mx[3][13] = {{0, -1, 0, 1, 0}, {-1, 0, 1, -1, 0, 1, -1, 0, 1}, {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}};

void disp(vector< vector<int> > &v){
  cout <<"-----------" <<endl;
  REP(i, H){
    REP(j, W) cout <<v[i][j];
    cout <<endl;
  }
}

bool check(vector< vector<int> > &v, int y, int x, int t){
  REP(i, l[t]){
    int ny = y + my[t][i], nx = x + mx[t][i];
    if(ny < 0 || nx < 0 || ny >= H || nx >= W || v[ny][nx] + 1 > tar[ny][nx]) return false;
  }
  return true;
}

vector< vector<int> > drop(vector< vector<int> > &v, int y, int x, int t){
  vector< vector<int> > ret = v;
  REP(i, l[t]){
    int ny = y + my[t][i], nx = x + mx[t][i];
    ret[ny][nx]++;
  }
  return ret;
}

void dfs(int now, vector<PP> &ps, vector< vector<int> > &v){
  if(now >= N){
    if(v == tar) ans = ps;
    return ;
  }
  REP(i, H){
    REP(j, W){
      REP(t, 3){
        if(check(v, i, j, t)){
          vector<PP> tps = ps;
          tps.push_back(PP(P(i, j), t));
          vector< vector<int> > tv = drop(v, i, j, t);
          dfs(now + 1, tps, tv);
        }
      }
    }
  }
}

int main() {
  cin >>N;
  tar = vector< vector<int> >(H, vector<int>(W));
  REP(i, H) REP(j, H) cin >>tar[i][j];
  vector<PP> ps;
  vector< vector<int> > v(H, vector<int>(W, 0));
  dfs(0, ps, v);
  REP(i, ans.size()) cout <<ans[i].first.second <<" " <<ans[i].first.first <<" " <<ans[i].second + 1 <<endl;
  return 0;
}