#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Answer {
  int y, x, size;
  Answer(int y_, int x_, int size_) : y(y_), x(x_), size(size_) { }
};

int N;
int board[10][10];
vector<Answer> ans;
bool done;

int small[5][2] = {
  { 0, 0 },
  { 1, -1 },
  { 1, 0 },
  { 1, 1 },
  { 2, 0 }
};

int middle[9][2] = {
  { 0, 0 },
  { 0, 1 },
  { 0, 2 },
  { 1, 0 },
  { 1, 1 },
  { 1, 2 },
  { 2, 0 },
  { 2, 1 },
  { 2, 2 }
};

int large[13][2] = {
  { 0, 0 },
  { 1, -1 },
  { 1, 0 },
  { 1, 1 },
  { 2, -2 },
  { 2, -1 },
  { 2, 0 },
  { 2, 1 },
  { 2, 2 },
  { 3, -1 },
  { 3, 0 },
  { 3, 1 },
  { 4, 0 }
};

bool check_small(int y, int x) {
  if(0 <= y && y <= 7 && 1 <= x && x <= 8) {
    for(int i = 0; i < 5; ++i) {
      int ny = y + small[i][0];
      int nx = x + small[i][1];
      if(board[ny][nx] < 1) return false;
    }
    return true;
  }
  return false;
}

bool check_middle(int y, int x) {
  if(0 <= y && y <= 7 && 0 <= x && x <= 7) {
    for(int i = 0; i < 9; ++i) {
      int ny = y + middle[i][0];
      int nx = x + middle[i][1];
      if(board[ny][nx] < 1) return false;
    }
    return true;
  }
  return false;
}

bool check_large(int y, int x) {
  if(0 <= y && y <= 5 && 2 <= x && x <= 7) {
    for(int i = 0; i < 13; ++i) {
      int ny = y + large[i][0];
      int nx = x + large[i][1];
      if(board[ny][nx] < 1) return false;
    }
    return true;
  }
  return false;
}

void solve(int y, int x) {
  //cerr << __func__ << "(y=" << y  + 1<< ", x=" << x + 1 << ")" << endl;
  //for(auto&& a : ans) {
  //  cerr << "put: " << (a.x + 1) << " " << (a.y + 1) << " " << (a.size + 1) << endl;
  //}
  //for(int y = 0; y < 10; ++y) {
  //  for(int x = 0; x < 10; ++x) {
  //    cerr << board[y][x];
  //  }
  //  cerr << endl;
  //}
  if(done) return;
  if(y > 9) {
    if(ans.size() == N) {
      for(auto&& a : ans) {
        cout << (a.x) << " " << (a.y) << " " << (a.size + 1) << endl;
      }
      done = true;
    }
    return;
  }
  if(x > 9) {
    solve(y + 1, 0);
    return;
  }
  if(board[y][x] > 0) {
    // small
    if(check_small(y, x)) {
      for(int i = 0; i < 5; ++i) {
        int ny = y + small[i][0];
        int nx = x + small[i][1];
        board[ny][nx]--;
      }
      ans.emplace_back(y + 1, x, 0);
      solve(y, x);
      ans.pop_back();
      for(int i = 0; i < 5; ++i) {
        int ny = y + small[i][0];
        int nx = x + small[i][1];
        board[ny][nx]++;
      }
    }
    // middle
    if(check_middle(y, x)) {
      for(int i = 0; i < 9; ++i) {
        int ny = y + middle[i][0];
        int nx = x + middle[i][1];
        board[ny][nx]--;
      }
      ans.emplace_back(y + 1, x + 1, 1);
      solve(y, x);
      ans.pop_back();
      for(int i = 0; i < 9; ++i) {
        int ny = y + middle[i][0];
        int nx = x + middle[i][1];
        board[ny][nx]++;
      }
    }
    // big
    if(board[y][x] == 1 && check_large(y, x)) {
      for(int i = 0; i < 13; ++i) {
        int ny = y + large[i][0];
        int nx = x + large[i][1];
        board[ny][nx]--;
      }
      ans.emplace_back(y + 2, x, 2);
      solve(y, x);
      ans.pop_back();
      for(int i = 0; i < 13; ++i) {
        int ny = y + large[i][0];
        int nx = x + large[i][1];
        board[ny][nx]++;
      }
    }
    return;
  }
  else {
    solve(y, x + 1);
  }
}

int main() {
  cin >> N;
  for(int i = 0; i < 10; ++i) {
    for(int j = 0; j < 10; ++j) {
      cin >> board[i][j];
    }
  }
  ans.clear();
  done = false;
  solve(0, 0);
}