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

int data[10][10];

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

void printSmall(int sx,int sy){
  cout << sx << ' ' << sy+1 << ' ' << 1 << endl;
}

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

void printNormal(int sx,int sy){
  cout << sx + 1 << ' ' << sy + 1 << ' ' << 2 << endl;
}

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

void printBig(int sx,int sy){
  cout << sx << ' ' << sy+2 << ' ' << 3 << endl;
}

bool check(int x,int y){
  if(!(0 <= x && x < 10))return false;
  if(!(0 <= y && y < 10))return false;
  return true;
}

bool isRemove(int x,int y,int ax[],int ay[],int len){
  for(int i = 0 ; i < len ; i++){
    int nx,ny;
    nx = x + ax[i];
    ny = y + ay[i];
    if(!check(nx,ny))return false;
    if(data[ny][nx] == 0)return false;
  }
  return true;
}

void remove(int x,int y,int ax[],int ay[],int len){
  for(int i = 0 ; i < len ; i++){
    int nx,ny;
    nx = x + ax[i];
    ny = y + ay[i];
    data[ny][nx]--;
  }
}

void draw(int x,int y,int ax[],int ay[],int len){
  for(int i = 0 ; i < len ; i++){
    int nx,ny;
    nx = x + ax[i];
    ny = y + ay[i];
    data[ny][nx]++;
  }
}

void display(){
  cout << "display" << endl;
  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      cout << data[i][j] << ' ';
    }
    cout << endl;
  }
}

bool dfs(int d,int x,int y,int rem){

  //cout << "d = " << d << " x = " << x << " y = " << y << " rem = " << rem << endl;//
  //display();

  if(d == 0 && rem == 0)return true;
  if(d == 0 && rem > 0)return false;

  if(data[y][x]){
    int rx,ry;
    if(isRemove(x,y,small_x,small_y,5)){
      remove(x,y,small_x,small_y,5);
      if(dfs(d-1,x,y,rem-5)){
	printSmall(x,y);
	return true;
      }
      draw(x,y,small_x,small_y,5);
    }

    if(isRemove(x,y,normal_x,normal_y,9)){
      remove(x,y,normal_x,normal_y,9);
      if(dfs(d-1,x,y,rem-9)){
	printNormal(x,y);
	return true;
      }
      draw(x,y,normal_x,normal_y,9);
    }
    
    if(isRemove(x,y,big_x,big_y,13)){
      remove(x,y,big_x,big_y,13);
      if(dfs(d-1,x,y,rem-13)){
	printBig(x,y);
	return true;
      }
      draw(x,y,big_x,big_y,13);
    }

    //cout << "?" << endl;
    return false;
  }

  bool f = false;
  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      if(!f){
	i = y;
	j = x+1;
	f = true;
	if(j >= 10)continue;
      }
      if(data[i][j])return dfs(d,j,i,rem);
    }
  }
  return false;
}

int main(){

  /*
  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      data[i][j] = 0;
    }
  }

  draw(5,5,big_x,big_y,13);
  display();

  return 0;
  */

  int d;
  cin >> d;
  int rem = 0;
  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      cin >> data[i][j];
      rem += data[i][j];
    }
  }
  dfs(d,0,0,rem);
  return 0;
}