#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
typedef pair<int,int> pii;
typedef pair<pii,int> Ink;

int mat[10][10];

int dx[3][13] = {
    {-1,0,0,1,0},
    {-1,-1,-1,0,0,0,1,1,1},
    {-2,-1,-1,-1,0,0,0,0,0,1,1,1,2}
};

int dy[3][13] = {
    {0,-1,0,0,1},
    {-1,0,1,-1,0,1,-1,0,1},
    {0,-1,0,1,-2,-1,0,1,2,-1,0,1,0}
};

bool inField(int x,int y){
    return (0 <= x && x < 10 && 0 <= y && y < 10);
}

bool check(){
    for(int i = 0 ; i < 10 ; i++){
        for(int j = 0 ; j < 10 ; j++){
            if(mat[i][j] != 0) return 0;
        }
    }
    return 1;
}

bool check2(int x,int y,int s,int t){
    int size[] = {5,9,13};
    for(int i = 0 ; i < size[s] ; i++){
        int nx = x + dx[s][i];
        int ny = y + dy[s][i];
        if(!inField(nx,ny)) continue;
        if(mat[ny][nx] < t) return 0;
    }
    return 1;
}

void func(int x,int y,int s,int order,int t){
    int size[] = {5,9,13};
    for(int i = 0 ; i < size[s] ; i++){
        int nx = x + dx[s][i];
        int ny = y + dy[s][i];
        if(!inField(nx,ny)) continue;
        mat[ny][nx] = mat[ny][nx] + (order == 1 ? t : -t);
    }
}

vector<Ink> v;

void solve(int x,int y,int s,int n){
    if(n == 0){
        if(check()) throw 0;
        return;
    }
    if(x == 9) return;
    if(y == 9){
        solve(x+1,1,0,n);
        return;
    }
    if(s == 3){
        solve(x,y+1,0,n);
        return;
    }
    solve(x,y,s+1,n);
    for(int i = 1 ; i <= 12 ; i++){
        if(check2(x,y,s,i) && n-i >= 0){
            func(x,y,s,0,i);
	    for(int j = 0 ; j < i ; j++){
		v.push_back(Ink(pii(x,y),s+1));
	    }
            solve(x,y+1,0,n-i);
            for(int j = 0 ; j < i ; j++){
		v.pop_back();
	    }
            func(x,y,s,1,i);
        }
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0 ; i < 10 ; i++){
        for(int j = 0 ; j < 10 ; j++){
            cin >> mat[i][j];
        }
    }
    try{
        solve(1,1,0,n);
    }catch(...){}
    for(int i = 0 ; i < (int)v.size() ; i++){
        cout << v[i].F.F << " " << v[i].F.S << " " << v[i].S << endl;
    }
    return 0;
}