#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    set<pair<int, int>> s1, s2;
    int fcol, scol, tcol;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if ((i + j) % 2) {
                s2.insert({i + 1, j + 1});
            }
            else {
                s1.insert({i + 1, j + 1});
            }
        }
    }
    int x;
    cin >> x;
    if (x == 1) {
        fcol = 2;
        scol = 1;
        tcol = 3;
    }
    else {
        fcol = 1;
        scol = 2;
        tcol = 3;
    }
    cout << fcol << ' ' << (*s1.begin()).first << ' ' << (*s1.begin()).second << '\n'; 
    s1.erase(s1.begin());
    cout.flush();
    for (int i = 0; i < n * n - 1; ++i) {
        cin >> x;
        if (x != fcol) {
            if (s1.size()) {
                cout << fcol << ' ' << (*s1.begin()).first << ' ' << (*s1.begin()).second << '\n'; 
                s1.erase(s1.begin());
                cout.flush();
            }
            else {
                cout << (scol != x ? scol : tcol) << ' ' << (*s2.begin()).first << ' ' << (*s2.begin()).second << '\n';
                s2.erase(s2.begin());
                cout.flush();
            }
        }
        else {
            if (s2.size()) {
                cout << scol << ' ' << (*s2.begin()).first << ' ' << (*s2.begin()).second << '\n'; 
                s2.erase(s2.begin());
                cout.flush();
            }
            else {
                cout << tcol << ' ' << (*s1.begin()).first << ' ' << (*s1.begin()).second << '\n';
                s1.erase(s1.begin());
                cout.flush();
            }
        }
    }
}