#include <bits/stdc++.h>
using namespace std;
const uint64_t seed =
    std::chrono::system_clock::now().time_since_epoch().count();
mt19937_64 rnd(seed);
const int MOD = 998244353;
void solve() {
  int n;
  cin >> n;
  vector<bool> a(6 * n, false);
  for (int i = 0; i < 3 * n; i++) {
    int t;
    cin >> t;
    a[t - 1] = true;
  }
  vector<int> ss;
  vector<tuple<int, int, int>> group(6 * n);
  vector<bool> groupHead(6 * n, false);
  vector<int> pa(6 * n, -1);
  vector<int> inCnt(6 * n, 0);
  for (int i = 0; i < 6 * n; i++) {
    if (ss.size() >= 2 && a[ss.back()] == a[i] &&
        a[ss[ss.size() - 2]] == a[i]) {
      int p = ss[ss.size() - 2];
      groupHead[p] = true;
      group[p] = {p, ss.back(), i};
      ;
      ss.pop_back();
      ss.pop_back();
      if (ss.size() >= 2 && a[ss.back()] == a[ss[ss.size() - 2]]) {
        pa[p] = ss[ss.size() - 2];
      } else if (ss.size() >= 1) {
        pa[p] = ss.back();
      }
    } else {
      ss.push_back(i);
    }
  };
  for (int i = 0; i < 6 * n; i++) {
    if (pa[i] != -1) {
      inCnt[pa[i]]++;
    }
  }
  queue<int> qq[2];
  for (int i = 0; i < 6 * n; i++) {
    if (inCnt[i] == 0 && groupHead[i]) {
      ;
      qq[a[i]].push(i);
    }
  };
  int c = 1;
  for (int i = 0; i < 2 * n; i++) {
    int p = qq[c].front();
    qq[c].pop();
    if (c == 0 && qq[c].size() > 0 && pa[p] == -1) {
      qq[c].push(p);
      p = qq[c].front();
      qq[c].pop();
    }
    int aa, bb, cc;
    tie(aa, bb, cc) = group[p];
    aa++, bb++, cc++;
    cout << aa << " " << bb << " " << cc << "\n";
    if (pa[p] != -1) {
      inCnt[pa[p]]--;
      if (inCnt[pa[p]] == 0) qq[a[pa[p]]].push(pa[p]);
    }
    c = 1 - c;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  int T = 1;
  for (int i = 1; i <= T; i++) {
    solve();
  }
  cout.flush();
  return 0;
}
