#include <bits/stdc++.h>
const int M = 10005;
int read() {
  int x = 0, f = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9') {
    if (c == '-') f = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
int n, m, k, a[M], b[M], c[M], d[M];
int s[M], fa[M], p[M][3], vis[M];
signed main() {
  n = read();
  for (int i = 1; i <= 3 * n; i++) a[read()] = 1;
  for (int i = 1; i <= 6 * n; i++) {
    if (!m || b[s[m]] != a[i]) {
      b[++k] = a[i];
      s[++m] = k;
      p[k][c[k]++] = i;
    } else {
      p[s[m]][c[s[m]]++] = i;
      if (c[s[m]] == 3) fa[s[m]] = s[m - 1], m--;
    }
  }
  int c = 1, cnt = 0;
  for (int i = 1; i <= k; i++) d[fa[i]]++;
  for (int i = 1; i <= k; i++)
    if (!fa[i] && !b[i]) cnt++;
  for (int i = 1; i <= k; i++) {
    int x = 0;
    for (int j = 1; j <= k; j++)
      if (!d[j] && b[j] == c && !vis[j]) {
        if (i < k && cnt == 1 && c == 0 && !fa[j]) continue;
        x = j;
      }
    d[fa[x]]--;
    c ^= 1;
    vis[x] = 1;
    if (b[x] == 0 && !fa[x]) cnt--;
    printf("%d %d %d\n", p[x][0], p[x][1], p[x][2]);
  }
}
