#include <iostream>
#include <algorithm>
#include <vector>
#include <random>
#include <tuple>
#include <iterator>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)

struct Answer {
  int y, x, size;
  Answer(int y_, int x_, int size_) : y(y_), x(x_), size(size_) { }
  bool operator <(const Answer &other) const {
    return tie(y, x, size) < tie(other.y, other.x, other.size);
  }
  bool operator ==(const Answer &other) const {
    return tie(y, x, size) == tie(other.y, other.x, other.size);
  }
};

int N;
int board[10][10];
vector<Answer> ans;
vector<Answer> actual;
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) {
  if(done) return;
  if(y > 9) {
    if(ans.size() == N) {
      for(auto &&a : ans) {
        cout << (a.x) << " " << (a.y) << " " << (a.size + 1) << endl;
      }
      actual = ans;
      sort(begin(actual), end(actual));
      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);
#if 0
      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;
      }
#endif
      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);
#if 0
      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;
      }
#endif
      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(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);
#if 0
      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;
      }
#endif
      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);
  }
}

void test();

int main() {
#if 0
  test();
#else
  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);
#endif
}

void test() {
  random_device dev;
  mt19937 engine(dev());
  uniform_int_distribution<int> drop_distrib(0, 12);
  uniform_int_distribution<int> size_distrib(0, 2);
  uniform_int_distribution<int> coord_distrib(0, 9);
  while(true) {
    vector<Answer> expect;
    int drop = drop_distrib(engine);
    for(int i = 0; i < drop; ++i) {
      bool ok = false;
      int y, x, size;
      do {
        y = coord_distrib(engine);
        x = coord_distrib(engine);
        size = size_distrib(engine);
        if(size == 0) {
          if(0 <= y && y <= 7 && 1 <= x && x <= 8)
            ok = true;
        }
        else if(size == 1) {
          if(0 <= y && y <= 7 && 0 <= x && x <= 7)
            ok = true;
        }
        else if(size == 2) {
          if(0 <= y && y <= 5 && 2 <= x && x <= 7)
            ok = true;
        }
      } while(ok == false);
      expect.emplace_back(y, x, size);
    }
    REP(y,10) REP(x,10) {
      board[y][x] = 0;
    }
    REP(i,drop) {
      if(expect[i].size == 0) {
        REP(j,5) {
          int ny = expect[i].y + small[j][0];
          int nx = expect[i].x + small[j][1];
          board[ny][nx]++;
        }
        expect[i].y++;
      }
      else if(expect[i].size == 1) {
        REP(j,9) {
          int ny = expect[i].y + middle[j][0];
          int nx = expect[i].x + middle[j][1];
          board[ny][nx]++;
        }
        expect[i].y++;
        expect[i].x++;
      }
      else if(expect[i].size == 2) {
        REP(j,13) {
          int ny = expect[i].y + large[j][0];
          int nx = expect[i].x + large[j][1];
          board[ny][nx]++;
        }
        expect[i].y += 2;
      }
    }
    sort(begin(expect), end(expect));
    N = expect.size();
    ans.clear();
    done = false;
    solve(0, 0);
    if(expect == actual) {
      cerr << "OK" << endl;
    }
    else {
      cerr << "NG" << endl;
      REP(y,10) {
        REP(x,10) {
          cerr << board[y][x] << ' ';
        }
        cerr << endl;
      }
      cerr << "expect:" << endl;
      cerr << expect.size() << endl;
      for(auto &&a: expect) {
        cerr << a.x << ' ' << a.y << ' ' << (a.size) << endl;
      }
      cerr << "actual:" << endl;
      cerr << actual.size() << endl;
      for(auto &&a: actual) {
        cerr << a.x << ' ' << a.y << ' ' << (a.size) << endl;
      }
      break;
    }
  }
}