#include <bits/stdc++.h>
using namespace std;
struct node {
  int a;
  int b;
  int c;
  vector<int> child;
};
vector<node> nodes;
vector<int> n_child;
vector<int> parent;
pair<int, int> build_tree(int color[], int i, int root) {
  node new_node;
  int nni = nodes.size();
  nodes.push_back(new_node);
  n_child.push_back(0);
  parent.push_back(root);
  nodes[nni].a = i;
  int first_color = color[i];
  i += 1;
  while (color[i] != first_color) {
    int c;
    tie(i, c) = build_tree(color, i, nni);
    nodes[nni].child.push_back(c);
    n_child[nni] += 1;
  }
  nodes[nni].b = i;
  i += 1;
  while (color[i] != first_color) {
    int c;
    tie(i, c) = build_tree(color, i, nni);
    nodes[nni].child.push_back(c);
    n_child[nni] += 1;
  }
  nodes[nni].c = i;
  return {i + 1, nni};
}
void print_node(int n, int d, int color[]) {
  for (int i = 0; i < d; i++) {
    printf("   |");
  }
  printf("-> (%d, %d, %d) %d\n", nodes[n].a + 1, nodes[n].b + 1, nodes[n].c + 1,
         color[nodes[n].a]);
  for (auto c : nodes[n].child) {
    print_node(c, d + 1, color);
  }
}
void print_tree(vector<int> *tree, int color[]) {
  for (auto n : *tree) {
    print_node(n, 0, color);
    printf("\n");
  }
}
int main() {
  int n;
  scanf("%d", &n);
  int color[6 * n];
  for (int i = 0; i < 6 * n; i++) {
    color[i] = 0;
  }
  for (int i = 0; i < 3 * n; i++) {
    int t;
    scanf("%d", &t);
    color[t - 1] = 1;
  }
  vector<int> tree;
  int i = 0;
  while (i < 6 * n) {
    int c;
    tie(i, c) = build_tree(color, i, -1);
    tree.push_back(c);
  }
  int cc = 1;
  vector<int> leafs[2];
  vector<int> root_leafs[2];
  for (int i = 0; i < 2 * n; i++) {
    if (n_child[i] == 0) {
      if (parent[i] == -1) {
        root_leafs[color[nodes[i].a]].push_back(i);
      } else {
        leafs[color[nodes[i].a]].push_back(i);
      }
    }
  }
  for (int i = 0; i < 2 * n; i++) {
    int j;
    if (leafs[cc].size()) {
      j = leafs[cc].back();
      leafs[cc].pop_back();
      int p = parent[j];
      n_child[p] -= 1;
      if (n_child[p] == 0) {
        if (parent[p] == -1) {
          root_leafs[1 - cc].push_back(p);
        } else {
          leafs[1 - cc].push_back(p);
        }
      }
    } else if (root_leafs[cc].size()) {
      j = root_leafs[cc].back();
      root_leafs[cc].pop_back();
    } else {
      printf("got stuck :(\n");
      return 0;
    }
    printf("%d %d %d\n", nodes[j].a + 1, nodes[j].b + 1, nodes[j].c + 1);
    cc = 1 - cc;
  }
  return 0;
}
