#include <bits/stdc++.h>
using namespace std;
std::mt19937 rnd(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200;
const int MAXCARD = 6 * MAXN;
int n, ncard;
int col[MAXCARD];
vector<vector<int>> ans;
bool can[MAXCARD][MAXCARD];
int prv[MAXCARD + 1][4];
vector<vector<int>> lst;
vector<int> par;
vector<vector<int>> ch;
vector<bool> done;
vector<int> rem;
void build(int s, int t) {
  vector<pair<int, vector<int>>> stck;
  for (int i = (s); i <= (t); ++i) {
    if (stck.empty() || stck.back().first != col[i]) {
      stck.push_back(make_pair(col[i], vector<int>(1, i)));
    } else {
      stck.back().second.push_back(i);
      if (((int)(stck.back().second).size()) == 3) {
        vector<int> cur = stck.back().second;
        lst.push_back(cur);
        stck.pop_back();
      }
    }
  }
  assert(((int)(stck).size()) == 0);
}
bool inside(const vector<int>& a, const vector<int>& b) {
  bool pos1 = true, pos2 = true;
  for (int i = (0); i < (((int)(a).size())); ++i) {
    if (a[i] < b[0] || a[i] > b[1]) pos1 = false;
    if (a[i] < b[1] || a[i] > b[2]) pos2 = false;
  }
  return pos1 || pos2;
}
bool conflicting(const vector<int>& a, const vector<int>& b) {
  if (inside(a, b) || inside(b, a)) return false;
  if (a[2] < b[0] || b[2] < a[0]) return false;
  return true;
}
void solve() {
  for (int s = (0); s < (ncard); ++s) {
    vector<pair<int, int>> stck;
    for (int i = (s); i < (ncard); ++i) {
      if (stck.empty() || stck.back().first != col[i])
        stck.push_back(make_pair(col[i], 1));
      else if (stck.back().second == 2)
        stck.pop_back();
      else
        ++stck.back().second;
      can[s][i] = stck.empty();
    }
  }
  for (int i = (0); i <= (ncard); ++i)
    for (int j = (0); j <= (3); ++j) prv[i][j] = -2;
  for (int i = (0); i < (ncard); ++i)
    if (col[i] == 1 && (i == 0 || can[0][i - 1])) prv[i][0] = -1;
  for (int i = (0); i < (ncard); ++i)
    for (int j = (0); j < (3); ++j)
      if (prv[i][j] != -2) {
        for (int k = (i + 1); k <= (ncard); ++k)
          if ((k == ncard || col[k] == 1) && (k == i + 1 || can[i + 1][k - 1]))
            prv[k][j + 1] = i;
      }
  assert(prv[ncard][3] != -2);
  vector<int> last;
  for (int i = prv[ncard][3], j = 2; i != -1; i = prv[i][j], --j)
    last.push_back(i);
  reverse(last.begin(), last.end());
  lst.clear();
  for (int j = (0); j <= (3); ++j) {
    int s = j == 0 ? 0 : last[j - 1] + 1;
    int t = j == 3 ? ncard - 1 : last[j] - 1;
    if (s <= t) build(s, t);
  }
  lst.push_back(last);
  int lastid = ((int)(lst).size()) - 1;
  assert(((int)(lst).size()) == ncard / 3);
  ch = vector<vector<int>>(((int)(lst).size()));
  par = vector<int>(((int)(lst).size()), -1);
  for (int i = (0); i < (((int)(lst).size())); ++i)
    for (int j = (i + 1); j < (((int)(lst).size())); ++j) {
      assert(!conflicting(lst[i], lst[j]));
      assert(!inside(lst[j], lst[i]));
      if (inside(lst[i], lst[j])) {
        bool direct = true;
        for (int k = (i + 1); k < (j); ++k)
          if (inside(lst[i], lst[k]) && inside(lst[k], lst[j])) {
            direct = false;
            break;
          }
        if (direct) {
          assert(col[lst[i][0]] != col[lst[j][0]]);
          par[i] = j;
          ch[j].push_back(i);
        }
      }
    }
  rem = vector<int>(((int)(lst).size()), 0);
  for (int i = (0); i < (((int)(lst).size())); ++i)
    rem[i] = ((int)(ch[i]).size());
  done = vector<bool>(((int)(lst).size()), false);
  ans.clear();
  for (int i = (0); i < (((int)(lst).size())); ++i) {
    int c = i % 2;
    int use = -1;
    for (int j = (0); j < (((int)(lst).size())); ++j)
      if (!done[j] && col[lst[j][0]] == c && rem[j] == 0) {
        use = j;
        break;
      }
    assert(use != -1);
    done[use] = true;
    if (par[use] != -1) --rem[par[use]];
    ans.push_back(lst[use]);
  }
}
void run() {
  scanf("%d", &n);
  ncard = 6 * n;
  for (int i = (0); i < (ncard); ++i) col[i] = 1;
  for (int i = (0); i < (3 * n); ++i) {
    int x;
    scanf("%d", &x);
    --x;
    col[x] = 0;
  }
  solve();
  for (int i = (0); i < (((int)(ans).size())); ++i) {
    for (int j = (0); j < (((int)(ans[i]).size())); ++j) {
      if (j != 0) printf(" ");
      printf("%d", ans[i][j] + 1);
    }
    puts("");
  }
}
int main() {
  run();
  return 0;
}
