#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cassert>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
int N;

struct P
{
  int x,y,type;
  P(int x = -1,int y = -1,int type = -1):x(x),y(y),type(type){}
};
int SMLx[3][12] = {{0,0,1,-1},{1,2,2,2,1,1,0,0},{0,0,0,0,1,1,1,2,-1,-1,-1,-2}};
int SMLy[3][12] = {{1,2,1,1},{0,0,1,2,1,2,1,2},{1,2,3,4,1,2,3,2,1,2,3,2}};
int SML[] = {4,8,12};
bool F;
int Cx[] = {0,1,0};
int Cy[] = {1,1,2};

void print(const VVI& G)
{
  cout << "print---" << endl;
  for(int i=0;i<10;i++)
    {
      for(int j=0;j<10;j++)
	{
	  cout << G[i][j] << " ";
	}
      cout << endl;
    }
  cout << endl;
}

bool check(VVI& G,int x,int y,int type)
{
  G[y][x]--;
  for(int i=0;i<SML[type];i++)
    {
      int nx = x + SMLx[type][i];
      int ny = y + SMLy[type][i];
      if(!(0 <= nx && nx < 10 && 0 <= ny && ny < 10) || G[ny][nx] <= 0)
	{
	  G[y][x]++;
	  for(int j=i-1;j>=0;j--)
	    {
	      nx = x + SMLx[type][j];
	      ny = y + SMLy[type][j];
	      G[ny][nx]++;
	    }
	  return false;
	}
      G[ny][nx]--;
    }
  return true;
}

void draw(VVI& G,int x,int y,int type)
{
  G[y][x]++;
  for(int i=0;i<SML[type];i++)
    {
      int nx = x + SMLx[type][i];
      int ny = y + SMLy[type][i];
      if(!(0 <= nx && nx < 10 && 0 <= ny && ny < 10))
	assert(false);	 	
      G[ny][nx]++;
    }
}


void dfs(VVI& G,int x,int y,int cnt,vector<P> perm)
{
  if(cnt > N)
    return;
    if(F)
    return;
      
  perm.push_back(P(-1,-1,-1));
  for(int i=y;i<10;i++)
    for(int j= (i == y?x:0);j<10;j++)
      if(G[i][j] >= 1)
	{
	  bool found = false;
	  for(int k=0;k<3;k++)
	    {
	      if(!check(G,j,i,k))
		continue;
	      perm[perm.size()-1] = P(j+Cx[k],i+Cy[k],k+1);
	      dfs(G,j,i,cnt+1,perm);
	      draw(G,j,i,k);
	    }
	  return;
	}


  if(cnt == N  && !F)
    {
      for(int i=0;i<N;i++)
	{
	  cout << perm[i].x << " " << perm[i].y << " " << perm[i].type << endl; 
	}      
      assert(!F);
      F = true;
    }
}

int main()
{
  F = false;
  cin >> N;
  assert(N <= 12);
  VVI G(10,VI(10));

  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      cin >> G[i][j];
  dfs(G,0,0,0,vector<P>());
  assert(F);
  return 0;
}

/*
-- output --
3 2 1
8 4 2
1 1 2
5 2 3
8 1 2
1 4 2
3 6 3
6 6 3
1 8 2

-- input --
9
1 1 1 0 0 1 0 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 2 2 2 1 1 2 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 1 1 1
1 1 2 1 1 1 1 2 1 1
0 1 1 1 2 2 1 1 1 0
1 1 2 1 1 1 1 1 0 0
1 1 1 1 0 0 1 0 0 0
1 1 1 0 0 0 0 0 0 0

*/