#include<iostream>
using namespace std;
int t[100][100];
int a[100][100];
int n,flg;

void print();
int T(int y,int x){
  if(0<=y&&y<10&&0<=x&&x<10)return t[y][x];
  return 1;
}

int Tdraw(int y,int x,int z){
  if(0<=y&&y<10&&0<=x&&x<10)t[y][x]+=z;
}

void drawsmall(int y,int x,int z){
  Tdraw(y,x,z);Tdraw(y+1,x,z);Tdraw(y-1,x,z);Tdraw(y,x-1,z);Tdraw(y,x+1,z);
}
void drawmid(int y,int x,int z){
  drawsmall(y,x,z);
  Tdraw(y+1,x+1,z);Tdraw(y-1,x-1,z);Tdraw(y+1,x-1,z);Tdraw(y-1,x+1,z);
}
void drawlarge(int y,int x,int z){
  drawmid(y,x,z);
  Tdraw(y+2,x,z);Tdraw(y-2,x,z);Tdraw(y,x-2,z);Tdraw(y,x+2,z);
}


bool small(int y,int x){
  if(T(y,x)>=1&&T(y+1,x)>=1&&T(y-1,x)>=1&&T(y,x-1)>=1&&T(y,x+1)>=1)return true;
  else return false;
}
bool mid(int y,int x){
  if(small(y,x)){
    if(T(y-1,x-1)>=1&&T(y+1,x-1)>=1&&T(y-1,x+1)>=1&&T(y+1,x+1)>=1){
      return true;
    }
  }
  return false;
}
bool large(int y,int x){
  if(mid(y,x)){
    if(T(y-2,x)>=1&&T(y+2,x)>=1&&T(y,x+2)>=1&&T(y,x-2)>=1){
      return true;
    }
  }
  return false;
}

void check(int y,int x,int cnt){
  /*
  cout<<y<<' '<<x<<' '<<cnt<<endl;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cout<<t[i][j];
    }
    cout<<endl;
  }
  */
  if(y==10&&x==0&&cnt==n){
    print();
    flg=1;
  }
  if(flg)return;
  if(cnt>n)return;

  if(t[y][x]==0)check((x==9?y+1:y),(x==9?0:x+1),cnt);

  if(large(y+2,x)&&y+2<10){
    drawlarge(y+2,x,-1);a[y+2][x]+=10000;
    check(y,x,cnt+1);
    drawlarge(y+2,x,1);a[y+2][x]-=10000;
  }
  if(small(y+1,x)&&y+1<10){
    drawsmall(y+1,x,-1);a[y+1][x]++;
    check(y,x,cnt+1);
    drawsmall(y+1,x,1);a[y+1][x]--;
  }
  if(mid(y+1,x+1)&&y+1<10&&x+1<10){
    drawmid(y+1,x+1,-1);a[y+1][x+1]+=100;
    check(y,x,cnt+1);
    drawmid(y+1,x+1,1);a[y+1][x+1]-=100;
  }

  
}


void dfs(int x,int cnt){
  if(flg)return;
  if(x==10){
    check(0,0,cnt);
    return;
  }
  if(small(0,x)){
    drawsmall(0,x,-1);
    a[0][x]++;
    dfs(x,cnt+1);
    a[0][x]--;
    drawsmall(0,x,1);
  }
  if(mid(0,x)){
    drawmid(0,x,-1);
    a[0][x]+=100;
    dfs(x,cnt+1);
    a[0][x]-=100;
    drawmid(0,x,1);
  }
  if(large(0,x)){
    drawlarge(0,x,-1);
    a[0][x]+=10000;
    dfs(x,cnt+1);
    a[0][x]-=10000;
    drawlarge(0,x,1);
  }
  dfs(x+1,cnt);
}

int main(){
  flg=0;
  cin>>n;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>t[i][j];
      a[i][j]=0;
      //cout<<t[i][j]<<' ';
    }
    //cout<<endl;
  }
  dfs(0,0);
  return 0;
}

void print(){
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      while(a[i][j]>=10000){
	cout<<i<<" "<<j<<" "<<'3'<<endl;
	a[i][j]-=10000;
      }
      while(a[i][j]>=100){
	cout<<i<<" "<<j<<" "<<'2'<<endl;
	a[i][j]-=100;
      }
      while(a[i][j]>=1){
	cout<<i<<" "<<j<<" "<<'1'<<endl;
	a[i][j]-=1;
      }
    }
  }
}