#include <bits/stdc++.h>
using namespace std;
pair<int, int> p(int a, int b) { return {min(a, b), max(a, b)}; }
struct Triangle {
  int a, b, c;
  int neis;
  vector<int> V;
};
int aloneVertex(const Triangle &t1, const Triangle &t2) {
  if (t1.a != t2.a && t1.a != t2.b && t1.a != t2.c) return t1.a;
  if (t1.b != t2.a && t1.b != t2.b && t1.b != t2.c) return t1.b;
  return t1.c;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<pair<int, int>, int> Mp;
    vector<Triangle> Vec(n - 2);
    for (int i = 0; i < n - 2; i++) {
      cin >> Vec[i].a >> Vec[i].b >> Vec[i].c;
      auto f = [&](int x, int y) -> void {
        if (Mp.count(p(x, y))) {
          int ii = Mp[p(x, y)];
          Vec[i].V.push_back(ii);
          Vec[ii].V.push_back(i);
          Mp.erase(Mp.find(p(x, y)));
        } else
          Mp[p(x, y)] = i;
      };
      f(Vec[i].a, Vec[i].b);
      f(Vec[i].b, Vec[i].c);
      f(Vec[i].c, Vec[i].a);
    }
    for (int i = 0; i < n - 2; i++) Vec[i].neis = Vec[i].V.size();
    vector<vector<int>> Hull(n + 1);
    for (auto x : Mp) {
      Hull[x.first.first].push_back(x.first.second);
      Hull[x.first.second].push_back(x.first.first);
    }
    function<void(int, int)> dfs = [&](int v, int p) -> void {
      cout << v << " ";
      for (int nei : Hull[v])
        if (nei != p && nei != 1) dfs(nei, v);
    };
    dfs(1, Hull[1][0]);
    cout << "\n";
    vector<bool> Used(n - 2, false);
    queue<int> Q;
    for (int i = 0; i < n - 2; i++)
      if (Vec[i].neis <= 1) Q.push(i);
    while (!Q.empty()) {
      int q = Q.front();
      Q.pop();
      Used[q] = true;
      cout << q + 1 << " ";
      for (int nei : Vec[q].V)
        if (!Used[nei] && --Vec[nei].neis == 1) Q.push(nei);
    }
    cout << "\n";
  }
  return 0;
}
