#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

vector<pii> ansa, ansb, ansc;


void dfs(int y, int x, vector<vector<int>> &v, vector<pii> &a, vector<pii> &b, vector<pii> &c, int less ){
    if( ansa.size() || ansb.size() || ansc.size() )return ;
    if(less <= 0){
        for(int i=y;i<10;i++){
            rep(j,10){
                if(v[i][j]==1)return ;
            }
        }
        ansa = a;
        ansb = b;
        ansc = c;
        
        return ;
    }
    rep(i,10){
        rep(j,10){
            if( v[i][j]==1 ){
                if( i+2 >= 10 )continue;
                if( j==0 || v[i+1][j-1]==0 ){
                    if(j+2 >= 10 )continue;
                    bool ng = false;
                    rep(k,3){
                        rep(l,3){
                            v[i+k][j+l] --;
                            if( v[i+k][j+l]<0 )ng = true;
                        }
                    }
                    a.push_back(pii(i+1,j+1));
                    if( !ng ) dfs(y, x, v, a, b, c, less-1);
                    a.pop_back();
                    rep(k,3){
                        rep(l,3){
                            v[i+k][j+l] ++;
                        }
                    }
                }
                else{
                    if( i+2 >= 10 || j+1 >= 10 )continue;
                    
                    int dx1[] = {0, 0, 0, -1, 1};
                    int dy1[] = {0, 1, 2, 1, 1};
                    
                    bool ng = false;
                    rep(k,5){
                        int ddy = i+dy1[k];
                        int ddx = j+dx1[k];
                        v[ddy][ddx]--;
                        if( v[ddy][ddx] < 0 )ng = true;
                    }
                    b.push_back(pii(i+1,j));
                    if( !ng ) dfs(y, x, v, a, b, c, less-1);
                    b.pop_back();
                    rep(k,5){
                        int ddy = i+dy1[k];
                        int ddx = j+dx1[k];
                        v[ddy][ddx]++;
                    }
                    
                    if(j+2>=10 || i+4 >= 10)continue;
                    
                    int dx2[] = {0, 0, -2, 2};
                    int dy2[] = {0, 4, 2, 2};
                    ng = false;
                    rep(k,4){
                        int ddy = i+dy2[k];
                        int ddx = j+dx2[k];
                        v[ddy][ddx]--;
                        if( v[ddy][ddx] < 0 )ng = true;
                    }
                    rep(k,3){
                        rep(l,3){
                            v[i+k+1][j+l-1]--;
                            if( v[i+k+1][j+l-1]<0 )ng = true;
                        }
                    }
                    c.push_back(pii(i+2,j));
                    if( !ng ) dfs(i, j, v, a, b, c, less-1);
                    c.pop_back();
                    rep(k,4){
                        int ddy = i+dy2[k];
                        int ddx = j+dx2[k];
                        v[ddy][ddx]++;
                    }
                    rep(k,3){
                        rep(l,3){
                            v[i+k+1][j+l-1]++;
                        }
                    }
                }
            }
        }
    }
}

int main(){
    int n;
    cin>>n;
    vector<vector<int>> v(10,vector<int>(10));
    
    rep(i,10)rep(j,10)cin>>v[i][j];
    
    vector<pii> a, b, c;    //3*3, +, ++
    
    dfs(0, 0, v, a, b, c, n);
    
    rep(i,ansa.size()){
        cout<<ansa[i].second<<" "<<ansa[i].first<<" "<<2<<endl;
    }
    rep(i,ansb.size()){
        cout<<ansb[i].second<<" "<<ansb[i].first<<" "<<1<<endl;
    }
    rep(i,ansc.size()){
        cout<<ansc[i].second<<" "<<ansc[i].first<<" "<<3<<endl;
    }
}