#include <iostream>
using namespace std;

int n;
int mat[102][102];
int i1=1, j1=1, i2=1, j2=2;
int i3=1, j3=0;
int tip=0;

void next(int &i, int &j){
	if(j==n) i++, j=1;
	else j++;
}

void turn(int a){
	if(tip==0){
		if(a==1){
			mat[i2][j2]=2;	
			cout<<2<<" "<<i2<<" "<<j2<<endl;
			int ok=0;
			do{
				next(i2, j2);
				if(i2>n){
					ok=1;
					break;
				}
			}while((i2+j2)%2==0);
			if(ok) tip=2;
		}
		else{
			mat[i1][j1]=1;	
			cout<<1<<" "<<i1<<" "<<j1<<endl;
			int ok=0;
			do{
				next(i1, j1);
				if(i1>n){
					ok=1;
					break;
				}
			}while((i1+j1)%2==1);
			if(ok) tip=1;
		}
	}
	else{
		int col=0;
		if(tip==a){
			col=a%3+1;
		}
		else col=6-tip-a;
		do{
			next(i3, j3);
		}while(mat[i3][j3]);
		mat[i3][j3]=col;
		cout<<col<<" "<<i3<<" "<<j3<<endl;
	}
}

int main(){
	cin>>n;
	int nrt=n*n;
	while(nrt--){
		int a;
		cin>>a;
		turn(a);
	}
	return 0;
}
