#include<cstdio>
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
class point{
public:
   int x,y;
   point(){}
   point(int _x,int _y){
      x = _x,y = _y;
   }
}ink[13] = {
   point(0,-1),point(-1,0),point(0,0),point(1,0),point(0,1),
   point(-1,-1),point(1,-1),point(-1,1),point(1,1),
   point(0,-2),point(-2,0),point(2,0),point(0,2)
};

class data{
public:
   int x,y,sz;
   data(){}
   data(int _x,int _y,int _sz){
      x = _x; y = _y; sz = _sz;
   }
};

data ans[13],part[13];

void dfs(int m);
void add(int x,int y,int sz);
void rm(int x,int y,int sz);

int field[10][10] = {0},n;

int main(void){
   scanf("%d",&n);
   rep(i,10)rep(j,10) scanf("%d",&field[i][j]);
   dfs(0);
   rep(i,n) printf("%d %d %d\n",ans[i].x,ans[i].y,ans[i].sz);
   return 0;
}

void add(int x,int y,int sz){
   rep(i,13){
      if(sz == 1 && i >= 5) break;
      if(sz == 2 && i >= 9) break;

      int _x = x+ink[i].x,_y = y+ink[i].y;
      if(0<=_x&&_x<10 && 0<=_y&&_y<10){
         field[_y][_x] += 1;
      }
   }
   return;
}

void rm(int x,int y,int sz){
      rep(i,13){
      if(sz == 1 && i >= 5) break;
      if(sz == 2 && i >= 9) break;

      int _x = x+ink[i].x,_y = y+ink[i].y;
      if(0<=_x&&_x<10 && 0<=_y&&_y<10){
         field[_y][_x] -= 1;
      }
   }
   return;
}

bool end_flag = false;
void dfs(int m){
   if(end_flag == true) return;
   if(m == n){
      bool flag = true;
      rep(i,10)rep(j,10){
         if(field[i][j] != 0) flag = false;
      }
      if(flag == true){
         rep(i,n){
            ans[i] = data(part[i].x,part[i].y,part[i].sz);
            end_flag = true;
         }
      }
      return;
   }

   rep(i,10){
      rep(j,10){
         int cnt = 0;
         rep(k,14){
            if(k == 5 && end_flag == false){
               if(cnt != 5) break;
               rm(j,i,1);
               part[m] = data(j,i,1);
               dfs(m+1);
               add(j,i,1);
            }
            else if(k == 9 && end_flag == false){
               if(cnt != 9) break;
               rm(j,i,2);
               part[m] = data(j,i,2);
               dfs(m+1);
               add(j,i,2);
            }
            else if(k == 13 && end_flag == false){
               if(cnt != 13) break;
               rm(j,i,3);
               part[m] = data(j,i,3);
               dfs(m+1);
               add(j,i,3);
               break;
            }

            int _x = j+ink[k].x,_y = i+ink[k].y;
            if(_x<0 || _y<0 || _x>=10 || _y>=10){
               break;
            }
            else if(field[_y][_x] > 0){
               cnt += 1;
            }
         }
      }
   }
   return;
}