#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, s[200005], top;
bool a[200005], col[200005];
int pos[200005][3], m, fa[200005], deg[200005];
stack<int> stk;
signed main() {
  n = read();
  for (register int i = (1); i <= (3 * n); ++i) a[read()] = 1;
  for (register int i = (1); i <= (6 * n); ++i) {
    s[++top] = i;
    if (top >= 3 && a[s[top]] == a[s[top - 1]] &&
        a[s[top - 1]] == a[s[top - 2]]) {
      m++;
      col[m] = a[s[top]];
      for (register int j = (0); j <= (2); ++j) pos[m][j] = s[top - (2 - j)];
      top -= 3;
      while (stk.size() && pos[m][0] < pos[stk.top()][0])
        fa[stk.top()] = m, deg[m]++, stk.pop();
      stk.push(m);
    }
  }
  vector<int> v0, v1;
  for (register int i = (1); i <= (m); ++i)
    if (!deg[i]) {
      if (col[i])
        v1.push_back(i);
      else
        v0.push_back(i);
    }
  for (register int i = (1); i <= (n); ++i) {
    int u = v1.back();
    v1.pop_back();
    printf("%d %d %d\n", pos[u][0], pos[u][1], pos[u][2]);
    --deg[fa[u]];
    if (!deg[fa[u]]) v0.push_back(fa[u]);
    if (!fa[v0.back()] && v0.size() >= 2)
      swap(v0[(int)v0.size() - 1], v0[(int)v0.size() - 2]);
    u = v0.back();
    v0.pop_back();
    printf("%d %d %d\n", pos[u][0], pos[u][1], pos[u][2]);
    --deg[fa[u]];
    if (!deg[fa[u]]) v1.push_back(fa[u]);
  }
  return 0;
}
