#include<iostream>
#include<vector>
#include<set>
using namespace std;
#define r(a) for(int a=0;a<10;a++)

struct pain{int x,y,s,t;};
vector<pain>vec;
set<int>se;

int n;
vector<vector<int> >c(10,vector<int>(10,0));

bool s(int i,int j){ if(!i||!j||i==9||j==9)return 0;if(c[i][j]&&c[i-1][j]&&c[i+1][j]&&c[i][j+1]&&c[i][j-1])return 1; return 0; }
bool m(int i,int j){ if(c[i-1][j-1]&&c[i-1][j+1]&&c[i+1][j-1]&&c[i+1][j+1])return 1; return 0; }
bool l(int i,int j){ if(c[i-2][j]&&c[i+2][j]&&c[i][j-2]&&c[i][j+2])return 1; return 0; }

void ds(int i,int j){ c[i][j]--;c[i-1][j]--;c[i+1][j]--;c[i][j+1]--;c[i][j-1]--; }
void dm(int i,int j){ c[i-1][j-1]--;c[i-1][j+1]--;c[i+1][j-1]--;c[i+1][j+1]--; }
void dl(int i,int j){ c[i-2][j]--;c[i+2][j]--;c[i][j-2]--;c[i][j+2]--; }

void is(int i,int j){ c[i][j]++;c[i-1][j]++;c[i+1][j]++;c[i][j+1]++;c[i][j-1]++; }
void im(int i,int j){ c[i-1][j-1]++;c[i-1][j+1]++;c[i+1][j-1]++;c[i+1][j+1]++; }
void il(int i,int j){ c[i-2][j]++;c[i+2][j]++;c[i][j-2]++;c[i][j+2]++; }

bool eval(){
    int suc=1;
    r(a)r(b)
    if(c[a][b])suc=0;
    if(suc){
        for(int k=0;k<vec.size();k++)
            while(vec[k].t--)cout<<vec[k].y<<" "<<vec[k].x<<" "<<vec[k].s<<endl;
        return 1;
    }
    return 0;
}
bool eva(int i,int j){
    int suc=1;
    for(int a=0;a<i-2;a++)for(int b=0;b<j-2;b++)
        if(c[a][b])suc=0;
    return suc;
}
int tr(vector<vector<int> >vec){
    int n1=0;
    for(int i=0;i<10;i++)
        for(int j=0;j<10;j++)
            n1+=10000*c[i][j]+100*i+j;
    return n1;
}
bool dfs(int i,int j){
    pain tp;
    tp.x=i;tp.y=j;
    tp.t=0;
    if(i>1&&i<8&&j>1&&j<8){
        if(s(i,j)&&m(i,j)&&l(i,j)){
            int co=0;
            tp.s=3;
            vec.push_back(tp);
            while((s(i,j)&&m(i,j)&&l(i,j))){
                dl(i,j);dm(i,j);ds(i,j);
                vec[vec.size()-1].t++;
                co++;
            }
            if(!eva(i,j))goto n1;
            if(se.find(tr(c))!=se.end())goto n1;
            
            if(eval())return 1;
            r(a)r(b)
                if(s(a,b)&&dfs(a,b))
                    return 1;
            se.insert(tr(c));
        n1: while(co--){
                il(i,j);im(i,j);is(i,j);
            }
            vec.pop_back();
        }
    }
    if(i>0&&i<9&&j>0&&j<9){
        if(s(i,j)&&m(i,j)){
            int co=0;
            tp.s=2;
            vec.push_back(tp);
            while((s(i,j)&&m(i,j))){
                
                dm(i,j);ds(i,j);
                vec[vec.size()-1].t++;
                co++;
            }
            if(!eva(i,j))goto n2;
            if(se.find(tr(c))!=se.end())goto n2;
            if(eval())return 1;
            r(a)r(b)
            if(s(a,b)&&dfs(a,b))
                return 1;
            se.insert(tr(c));
        n2: while(co--){
                im(i,j);is(i,j);
            }
            vec.pop_back();
        }
        if(s(i,j)){
            int co=0;
            tp.s=1;
            vec.push_back(tp);
            while((s(i,j))){
                ds(i,j);
                tp.s=1;
                vec[vec.size()-1].t++;
                co++;
            }
            if(!eva(i,j))goto n3;
            if(se.find(tr(c))!=se.end())goto n3;
            if(eval())return 1;
            r(a)r(b)
            if(s(a,b)&&dfs(a,b))
                return 1;
            se.insert(tr(c));
        n3: while(co--){
                is(i,j);
            }
            vec.pop_back();
        }
    }
    return 0;
}
int main(){
    cin>>n;
    r(i)r(j)
    cin>>c[i][j];
    r(i)r(j){
        if(s(i,j))dfs(i,j);
    }
}