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

const int maxn = 110;
int n,g[maxn][maxn],vis[maxn][maxn],t;

struct node{
	int x,y;
};

queue<node> qw,qb;
void init(){
	bool flag = 1;
	for(int i = 1;i <= n;i++){
		flag = i%2;
		for(int j = 1;j <= n;j++){
			if(flag){
				g[i][j] = 1;
				qw.push({i,j});
			}else{
				qb.push({i,j});
			}
			if(flag) flag = 0;
			else flag = 1;
		}
	}
}


int main(){
	//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
	init();
	for(int i = 1;i <= n*n;i++){
		cin>>t;
		if(qw.size() && qb.size()){
			if(t == 1){
				int x = qb.front().x,y = qb.front().y;qb.pop();
				cout<<2<<" "<<x<<" "<<y<<endl;
			}
			else{
				int x = qw.front().x,y = qw.front().y;qw.pop();
				cout<<1<<" "<<x<<" "<<y<<endl;
			} 
		}else if(qw.size()){
			int x = qw.front().x,y = qw.front().y;qw.pop();
			if(t == 1) cout<<3<<" "<<x<<" "<<y<<endl;
			else cout<<1<<" "<<x<<" "<<y<<endl;
		}else{
			int x = qb.front().x,y = qb.front().y;qb.pop();
			if(t == 2) cout<<3<<" "<<x<<" "<<y<<endl;
			else cout<<2<<" "<<x<<" "<<y<<endl;
		}
	}
	cout.flush();
	return 0;
}