#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()a
#define ll long long
//#define int ll

const int N = 3e5 + 3;
const int inf = 1e9 + 3;
const int md = 1e9 + 7;

int n, q, x;
vector<pair<int, int> > a;
vector<pair<int, int> > b;

int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> n;
    for(int i = 1; i <= n; ++i) {
    	for(int j = 1; j <= n; ++j) {
    		if((i + j) % 2 == 0) a.push_back(make_pair(i, j));
    		else b.push_back(make_pair(i, j));
    	}
    }
    for(int j = 1; j <= n * n; ++j){
    	cin >> x;

    	if(a.empty()) {
    		pair<int, int> p = b.back();
    		b.pop_back();
    		if(x == 2) x = 3;
    		else x = 2;
    		cout << x << ' ' << p.first << ' ' << p.second << endl;
    		cout.flush();
    		continue;
    	} else if(b.empty()) {
    		pair<int, int> p = a.back();
    		a.pop_back();
    		if(x == 1) x = 3;
    		else x = 1;
    		cout << x << ' ' << p.first << ' ' << p.second << endl;
    		cout.flush();
    		continue;
    	}

    	if(x > 1) {
    		pair<int, int> p = a.back();
    		a.pop_back();
    		cout << 1 << ' ' << p.first << ' ' << p.second << endl;
    		cout.flush();
    	} else {
    		pair<int, int> p = b.back();
    		b.pop_back();
    		cout << 2 << ' ' << p.first << ' ' << p.second << endl;
    		cout.flush();
    	}
    }

}
