#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;

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}};

set<PP> ans;
//set< set<PP> > S;

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 < 0) return false;
  }
  return true;
}

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

bool isValid(vector< vector<int> > &v){
  REP(i, H) REP(j, W) if(v[i][j] > 0) return false;
  return true;
}

void dfs(int now, vector< vector<int> > &v, set<PP> &ps, int sy, int sx){
  if(now >= N){
    if(isValid(v)) ans = ps;
    return ;
  }
  //if(S.find(ps) != S.end()) return ;
  //S.insert(ps);
  FOR(y, sy, H){
    FOR(x, (y == sy ? sx : 0), W){
      if(v[y][x] <= 0) continue;
      if(check(v, y - 1, x, 0)){
        add(v, y - 1, x, 0, -1);
        set<PP> nps = ps;
        nps.insert(PP(P(y - 1, x), 0));
        dfs(now + 1, v, nps, y, x);
        add(v, y - 1, x, 0, 1);
      }
      if(check(v, y - 1, x - 1, 1)){
        add(v, y - 1, x - 1, 1, -1);
        set<PP> nps = ps;
        nps.insert(PP(P(y - 1, x - 1), 1));
        dfs(now + 1, v, nps, y, x);
        add(v, y - 1, x - 1, 1, 1);
      }
      if(check(v, y - 2, x, 2)){
        add(v, y - 2, x, 2, -1);
        set<PP> nps = ps;
        nps.insert(PP(P(y - 2, x), 2));
        dfs(now + 1, v, nps, y, x);
        add(v, y - 2, x, 2, 1);
      }
    }
  }
}

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