#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;

int cc = 0;

bool allZero(vector<vector<int>> v){
    rep(i,10){
        rep(j,10){
            if(v[i][j]!=0)return false;
        }
    }
    return true;
}

bool add1(int y, int x, vector<vector<int>> &v, int val){
    bool neg = false;
    rep(dx,3){
        rep(dy,3){
            v[y+dy][x+dx] += val;
            if( v[y+dy][x+dx]<0 )neg = true;
        }
    }
    return neg;
}

bool add2(int y, int x, vector<vector<int>> &v, int val){
    bool neg = false;
    int dx[] = {-1,0,0,0,1};
    int dy[] = {1,0,1,2,1};
    rep(i,5){
        v[y+dy[i]][x+dx[i]] += val;
        if( v[y+dy[i]][x+dx[i]]<0 )neg = true;
    }
    return neg;
}

bool add3(int y, int x, vector<vector<int>> &v, int val){
    bool neg = false;
    int dx[] = {-2,0,0,2};
    int dy[] = {2,0,4,2};
    rep(i,4){
        v[y+dy[i]][x+dx[i]] += val;
        if( v[y+dy[i]][x+dx[i]]<0 )neg = true;
    }
    rep(dx,3){
        rep(dy,3){
            v[y+dy+1][x+dx-1] += val;
            if( v[y+dy+1][x+dx-1]<0 )neg = true;
        }
    }
    return neg;
}

void dfs(vector<vector<int>> &v, vector<pii> &a, vector<pii> &b, vector<pii> &c, int less ){
    cc++;
    //    if( ansa.size() || ansb.size() || ansc.size() )return ;
    if(less <= 0){
        if( !allZero( v ) )return ;
        ansa = a;
        ansb = b;
        ansc = c;
        
        return ;
    }
    [&](){
        rep(i,10){
            rep(j,10){
                if(v[i][j]!=0){
                    if( i+2<10 && j+2<10 ){ //3*3
                        bool hasNeg = add1(i, j, v, -1);
                        a.push_back(pii(i+1,j+1));
                        if( !hasNeg )dfs(v, a, b, c, less-1);
                        a.pop_back();
                        add1(i, j, v, 1);
                    }
                    if( i+2<10 && 0<j && j+1<10 ){ //+
                        bool hasNeg = add2(i, j, v, -1);
                        b.push_back(pii(i+1,j));
                        if( !hasNeg )dfs(v, a, b, c, less-1);
                        b.pop_back();
                        add2(i, j, v, 1);
                    }
                    if( i+4<10 && 1<j && j+2<10 ){ //++
                        bool hasNeg = add3(i, j, v, -1);
                        c.push_back(pii(i+2,j));
                        if( !hasNeg )dfs(v, a, b, c, less-1);
                        c.pop_back();
                        add3(i, j, v, 1);
                    }
                    return ;
                }
            }
        }
    }();
}

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(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;
    }
}

Measured memory_bytes: 3148