#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define ll long long
#define MOD 998244353ll
#define MOD2 1000000009ll
#define MOD3 998244353ll
#define INF 1e16
#define MIN(a,b) (a>b?b:a)
using namespace std;
#define mp make_pair
#define pb push_back
#define  piii pair<pair<ll,ll>,ll>
#define pii pair<ll,ll>
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )
#define MAXN 500005
ll n,ar[105][105];
vector <pii> even,odd;
int main()
{
	cin>>n;
	ll a=1,b=2,c=3;
	rep(i,1,n+1)
	rep(j,1,n+1)
	{
		if((i+j)%2)
			odd.pb(mp(i,j));
		else
			even.pb(mp(i,j));
	}

	ll col;
	rep(i,0,n*n)
	{
		cin>>col;
		if(col==1)
		{
			if(!odd.empty())
			{
				pii p=*odd.rbegin();
				odd.pop_back();
				cout<<2<<" "<<p.fi<<" "<<p.se<<"\n";
			}
			else
			{
				pii p=*even.rbegin();
				even.pop_back();
				cout<<3<<" "<<p.fi<<" "<<p.se<<"\n";
			}
		}
		else if(col==2)
		{
			if(!even.empty())
			{
				pii p=*even.rbegin();
				even.pop_back();
				cout<<1<<" "<<p.fi<<" "<<p.se<<"\n";
			}
			else
			{
				pii p=*odd.rbegin();
				odd.pop_back();
				cout<<3<<" "<<p.fi<<" "<<p.se<<"\n";
			}
		}
		else
		{
			if(!odd.empty())
			{
				pii p=*odd.rbegin();
				odd.pop_back();
				cout<<2<<" "<<p.fi<<" "<<p.se<<"\n";
			}	
			else if(!even.empty())
			{
				pii p=*even.rbegin();
				even.pop_back();
				cout<<1<<" "<<p.fi<<" "<<p.se<<"\n";
			}		
		}
	}
}