#include<bits/stdc++.h>
#define LL long long
#define dl double
#define P pair<int,int>
template <class T>
void rd(T &x){
  x=0;T f=1;char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  while(ch<='9' && ch>='0'){x=x*10+ch-'0';ch=getchar();}x*=f;
}

using namespace std;

const int N = 105;

int n;
vector<P>p,q;

void out(int u,int v,int w){cout << w << " " << u << " " << v << endl;}

int main(){
  // freopen("in.txt","r",stdin);
  // freopen("o.txt","w",stdout);
  rd(n);
  for(int i = 1;i <= n;i++)
    for(int j = 1;j <= n;j++)
      if((i + j) & 1)p.emplace_back(i,j);
      else q.emplace_back(i,j);
  for(int i = 1;i <= n * n;i++){
    int x;rd(x);
    if(x != 1){
      if(!p.empty()){
        auto [u,v] = p.back();p.pop_back();
        out(u,v,1);
        // a[u][v] = 1;
      }
      else {
        auto [u,v] = q.back();q.pop_back();
        out(u,v,(x == 2) ? 3 : 2);
        // a[u][v] = (x == 2) ? 3 : 2;
      }
    }
    else if(x != 2){
      if(!q.empty()){
        auto [u,v] = q.back();q.pop_back();
        out(u,v,2);
        // a[u][v] = 2;
      }
      else {
        auto [u,v] = p.back();p.pop_back();
        out(u,v,(x == 3) ? 1 : 3);
        // a[u][v] = (x == 3) ? 1 : 3;
      }
    }
  }
  return 0;
}
/**/