#include <bits/stdc++.h>
using namespace std;
const string __sep = "\n";
struct triple {
  int x, y, z;
  triple(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int Q = 1;
  cin >> Q;
  while (Q-- > 0) {
    int n;
    cin >> n;
    unordered_map<int, set<int>> v2slice(n);
    vector<triple> triples;
    for (int i = 0; i + 2 < n; ++i) {
      int x, y, z;
      cin >> x >> y >> z;
      --x;
      --y;
      --z;
      v2slice[x].insert(i);
      v2slice[y].insert(i);
      v2slice[z].insert(i);
      triples.emplace_back(triple(x, y, z));
    }
    map<int, set<int>> qq;
    for (int i = 0; i < n; ++i) {
      qq[v2slice[i].size()].insert(i);
    }
    vector<int> cutvs;
    vector<int> cutting;
    int u, w;
    while (!qq[1].empty()) {
      int v = *qq[1].begin();
      qq[1].erase(qq[1].begin());
      assert(v2slice[v].size() == 1);
      int tr = *v2slice[v].begin();
      cutting.push_back(tr);
      cutvs.push_back(v);
      v2slice[v].erase(v2slice[v].begin());
      triple trr = triples[tr];
      set<int> tmp = {trr.x, trr.y, trr.z};
      tmp.erase(tmp.find(v));
      vector<int> tmpv(tmp.begin(), tmp.end());
      u = tmpv[0];
      w = tmpv[1];
      v2slice[u].erase(tr);
      v2slice[w].erase(tr);
      qq[v2slice[u].size() + 1].erase(qq[v2slice[u].size() + 1].find(u));
      if (!v2slice[u].empty()) qq[v2slice[u].size()].insert(u);
      qq[v2slice[w].size() + 1].erase(qq[v2slice[w].size() + 1].find(w));
      if (!v2slice[w].empty()) qq[v2slice[w].size()].insert(w);
    }
    vector<int> next(n, -1);
    next[u] = w;
    next[w] = u;
    for (int i = n - 3; i >= 0; --i) {
      int v = cutvs[i];
      int tr = cutting[i];
      triple trr = triples[tr];
      set<int> tmp = {trr.x, trr.y, trr.z};
      tmp.erase(tmp.find(v));
      vector<int> tmpv(tmp.begin(), tmp.end());
      int u = tmpv[0];
      int w = tmpv[1];
      if (next[u] == w) swap(u, w);
      assert(next[w] == u);
      next[w] = v;
      next[v] = u;
    }
    cout << 1 << " ";
    int curv = next[0];
    while (curv != 0) {
      cout << curv + 1 << " ";
      curv = next[curv];
    }
    cout << "\n";
    for (auto it : cutting) {
      cout << 1 + (it) << " ";
    }
    cout << "\n";
  }
  return 0;
}
