#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
 
#define MSIZE 10
#define PSIZE 5
 
vector < vector <int> > M; // ツ布
vector < vector <int> > S; // ツ禿、ツづ個技ツ術
 
const int P[3][PSIZE][PSIZE] = 
{
    {
        { 0, 0, 0, 0, 0 },
        { 0, 0, 1, 0, 0 },
        { 0, 1, 1, 1, 0 },
        { 0, 0, 1, 0, 0 },
        { 0, 0, 0, 0, 0 }
    },
    {
        { 0, 0, 0, 0, 0 },
        { 0, 1, 1, 1, 0 },
        { 0, 1, 1, 1, 0 },
        { 0, 1, 1, 1, 0 },
        { 0, 0, 0, 0, 0 }
    },
    {
        { 0, 0, 1, 0, 0 },
        { 0, 1, 1, 1, 0 },
        { 1, 1, 1, 1, 1 },
        { 0, 1, 1, 1, 0 },
        { 0, 0, 1, 0, 0 }
    }
};
 
void remove( int x, int y, int s )
{
    for ( int i = -2; i <= 2; i++ )
    {
        for ( int j = -2; j <= 2; j++ )
        {
            int px = j + 2;
            int py = i + 2;
 
            if ( P[s][py][px] == 0 )
                continue;
 
            int mx = x + j;
            int my = y + i;
 
            if ( ( mx < 0 || mx >= MSIZE ) || ( my < 0 || my >= MSIZE ) )
                continue;
 
            M[my][mx]--;
 
        }
    }
}
 
void add( int x, int y, int s )
{
    for ( int i = -2; i <= 2; i++ )
    {
        for ( int j = -2; j <= 2; j++ )
        {
            int px = j + 2;
            int py = i + 2;
 
            if ( P[s][py][px] == 0 )
                continue;
 
            int mx = x + j;
            int my = y + i;
 
            if ( ( mx < 0 || mx >= MSIZE ) || ( my < 0 || my >= MSIZE ) )
                continue;
 
            M[my][mx]++;
 
        }
    }
}
 
void add_s( int x, int y, int s )
{
    for ( int i = -2; i <= 2; i++ )
    {
        for ( int j = -2; j <= 2; j++ )
        {
            int px = j + 2;
            int py = i + 2;
 
            if ( P[s][py][px] == 0 )
                continue;
 
            int mx = x + j;
            int my = y + i;
 
            if ( ( mx < 0 || mx >= MSIZE ) || ( my < 0 || my >= MSIZE ) )
                continue;
 
            S[my][mx] = 1;
 
        }
    }
}
 
// ツピツーツスツつェツ債&#65533;つ、ツつゥツづ&#65533;つ、ツつゥツづーツ陳イツづ猟づゥ
bool check( int x, int y, int s )
{
    bool exist = true;
    for ( int i = -2; exist && i <= 2; i++ )
    {
        for ( int j = -2; exist && j <= 2; j++ )
        {
            int px = j + 2;
            int py = i + 2;
 
            if ( P[s][py][px] == 0 )
                continue;
 
            int mx = x + j;
            int my = y + i;
 
            if ( ( mx < 0 || mx >= MSIZE ) || ( my < 0 || my >= MSIZE ) )
                continue;
 
            // cout << s << ": (" << x << "," << y << ") - " << "(" << mx << "," << my << ")" << endl;
 
            if ( M[my][mx] == 0 )
            {
                // cout << s << ": (" << x << "," << y << ")" << endl;
                exist = false;
            }
 
        }
    }
    return exist;
}
 
int main( void )
{
    int N; // ツ静オツ猟ソツづ個古つ青&#65533; while ( cin >> N && N != -1 )
    cin >> N;
    {
        // ツマツッツプツづ個催ャツ青ャ
        M = vector < vector <int> >( MSIZE, vector <int>( MSIZE, 0 ) );
        for ( int i = 0; i < MSIZE; i++ )
        {
            for ( int j = 0; j < MSIZE; j++ )
            {
                int in;
                cin >> in;
                M[i][j] = in;
            }
        }
 
        // ツつサツづェツつシツづェツづ個ピツーツスツづ個古ウツ陛「ツづーツ探ツつキ
        int list_cnt = 0;
        vector <int> list_x;
        vector <int> list_y;
        vector <int> list_s;
        for ( int i = 2; i >= 0; i-- ) for ( int j = 0; j < MSIZE; j++ ) for ( int k = 0; k < MSIZE; k++ )
        {
            if ( M[j][k] != 0 )
            {
                if ( check( k, j, i ) )
                {
                    // ツ古ウツ陛「ツ板ュツ個ゥツ！ツ！
                    // cout << "!! (" << k << "," << j << ") " << i << endl;
                    list_x.push_back( k );
                    list_y.push_back( j );
                    list_s.push_back( i );
                    list_cnt++;
                }
            }
        }
 
        // listツづ可嘉ーツつェツ堕カツ催敖つキツづゥ
 
 
        vector < vector <int> > backup = M;
        for ( int li = 0; li < list_cnt; li++ )
        {
            // cout << list_s[i] << ": (" << list_x[i] << "," << list_y[i] << ")" << endl;
            //  ツ妥・ツつォツつ「ツづ卍つ、ツつゥツづァツ渉ャツつウツつ「ツづ卍つ、ツづ&#65533;           //  1. ツつサツづ個古ウツ陛「ツづーツ外ツつオツづ&#65533;づ敖づゥ
            //  2. ツづ&#65533;づ個ピツーツスツづーツ使ツづ&#65533;づ&#65533;づ&#65533;偲&#65533;個サツづ&#65533;つォツづ按つ「ツ湘ェツ渉環つェツつ&#65533;づゥツづ按づァツづ&#65533;            //      1. ツ古ウツ陛「ツつゥツづァツ外ツつキ
            //  3. ツ個ウツづ可姪淞つキ
 
            M = backup;
            S = vector < vector <int> > ( MSIZE, vector <int>( MSIZE, 0 ) );
            remove( list_x[li], list_y[li], list_s[li] );
 
            /*
            cout << ":: before" << endl;
            for ( int i = 0; i < MSIZE; i++ )
            {
                for ( int j = 0; j < MSIZE; j++ )
                {
                    cout <<"|"<< M[i][j] << "|";
                }
                cout << endl;
            }
            cout << endl;
 
            cout << list_x[li] << " " << list_y[li] << " " << list_s[li] << endl;
            remove( list_x[li], list_y[li], list_s[li] );
 
            cout << ":: after" << endl;
            for ( int i = 0; i < MSIZE; i++ )
            {
                for ( int j = 0; j < MSIZE; j++ )
                {
                    cout <<"|"<< M[i][j] << "|";
                }
                cout << endl;
            }
            cout << endl;
            */
 
            // check okツづ按づ&#65533;つアツづォツづーツづ&#65533;づアツづ&#65533;づアツ鳴&#65533;づ淞猟ァツづ&#65533;づゥ
            // ツ鳴&#65533;づ淞猟ァツづ&#65533;古」ツ、ツ鳴&#65533;づ淞猟ァツづ&#65533;づァツづェツづ&#65533;鳴ウツつ「ツ湘ェツ渉環つェツつ&#65533;づゥツづ按づァツ篠クツ格
            for ( int i = 0; i < MSIZE; i++ )
            {
                for ( int j = 0; j < MSIZE; j++ )
                {
                    for ( int k = 0; k < 3; k++ )
                    {
                        if ( M[i][j] != 0 && check( j, i, k ) )
                        {
                            add_s( j, i, k );
                        }
                    }
                }
            }
 
            bool checkok = true;
            for ( int i = 0; checkok && i < MSIZE; i++ )
            {
                for ( int j = 0; checkok && j < MSIZE; j++ )
                {
                    if ( M[i][j] >= 1 && S[i][j] == 0 )
                    {
                        checkok = false;
                    }
                }
            }
 
            if ( checkok )
            {
                cout << list_x[li] << " " << list_y[li] << " " << list_s[li] + 1 << endl;
            }
 
        }
 
        M = backup;
        for ( int i = 0; i < list_cnt; i++ )
        {
            // cout << list_x[i] << " " << list_y[i] << " " << list_s[i] + 1 << endl;
        }
 
        /*
        remove( list_x[0], list_y[0], list_s[0] );
        for ( int i = 0; i < MSIZE; i++ )
        {
            for ( int j = 0; j < MSIZE; j++ )
            {
                cout << "|" << M[i][j] << "|";
            }
            cout << endl;
        }
        cout << endl;
        add( list_x[0], list_y[0], list_s[0] );
        for ( int i = 0; i < MSIZE; i++ )
        {
            for ( int j = 0; j < MSIZE; j++ )
            {
                cout << "|" << M[i][j] << "|";
            }
            cout << endl;
        }
        cout << endl;
        */
    }
    return 0;
}