#include <iostream> 
#include <algorithm>
#include <map>

using namespace std;

static const int N = 10;

int n, data[N][N], v_size, rem, f[157];
pair<int, int> vis[15];
int size[3] = {5, 9, 13};
int cen[3] = {N, N+1, 2*N};
int dx[3][13] = {
  {0, -1, 0, 1, 0},
  {0, 1, 2, 0, 1, 2, 0, 1, 2},
  {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}
};
int dy[3][13] = {
  {0, 1, 1, 1, 2},
  {0, 0, 0, 1, 1, 1, 2, 2, 2},
  {0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4}
};

bool check(int p, int s){
  int x = p % N, y = p / N;
  for(int i=0;i<size[s];i++){
    int ny = y + dy[s][i];
    int nx = x + dx[s][i];
    if(ny >= N) return false;
    if(nx < 0 || nx >= N) return false;
    if(data[ny][nx] <= 0) return false;
  }
  return true;
}

void put(int p, int s, int t){
  int x = p % N, y = p / N;
  for(int i=0;i<size[s];i++){
    int ny = y + dy[s][i];
    int nx = x + dx[s][i];
    data[ny][nx] += t;
  }
}

bool solve(int p){
  if(rem < 0 || rem > 156 || !f[rem]) return false;
  if(v_size == n){
    if(rem == 0){
      for(int i=0;i<v_size;i++){
	cout << vis[i].first % N << ' ' << vis[i].first / N << ' ' << vis[i].second + 1 << endl;
      }
    }
    return rem == 0;
  }
  for(;p<N*N;p++){
    if(data[p/N][p%N] > 0){
      for(int i=0;i<3;i++){
	if(rem - size[i] < 0 || rem - size[i] > 156 || !f[rem-size[i]]) continue;
	if(check(p, i)){
	  put(p, i, -1);
	  rem -= size[i];
	  vis[v_size++] = make_pair(p+cen[i], i);
	  if(solve(p)) return true;
	  v_size--;
	  rem += size[i];
	  put(p, i, 1);
	}
      }
    }
  }
  return false;
}

int main(){
  for(int i=0;i<=12;i++){
    for(int j=0;j<=12;j++){
      for(int k=0;k<=12;k++){
	if(i + j + k <= 12){
	  int sum = 0;
	  for(int l=0;l<i;l++) sum += 5;
	  for(int l=0;l<j;l++) sum += 9;
	  for(int l=0;l<k;l++) sum += 13;
	  if(sum <= 156) f[sum] = true;
	}
      }
    }
  }
  cin >> n;
  rem = 0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin >> data[i][j];
      rem += data[i][j];
    }
  }
  solve(0);
  return 0;
}