#include <bits/stdc++.h>
using namespace std;
template <class T>
bool mini(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool maxi(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    map<pair<int, int>, set<int>> tria;
    auto add = [&](int u, int v, int id) {
      if (u > v) swap(u, v);
      tria[{u, v}].insert(id);
    };
    struct TRIA {
      int a, b, c;
    };
    vector<TRIA> a(n - 2);
    for (int i = 0; i < (int)(n - 2); i++) {
      cin >> a[i].a >> a[i].b >> a[i].c;
      a[i].a--;
      a[i].b--;
      a[i].c--;
      add(a[i].a, a[i].b, i);
      add(a[i].b, a[i].c, i);
      add(a[i].c, a[i].a, i);
    }
    vector<vector<int>> G(n);
    for (auto e : tria) {
      if (e.second.size() == 1) {
        int u = e.first.first, v = e.first.second;
        G[u].push_back(v);
        G[v].push_back(u);
      }
    }
    vector<int> order;
    vector<bool> was(n);
    function<void(int, int)> dfs = [&](int u, int p) {
      order.push_back(u);
      was[u] = 1;
      for (int v : G[u])
        if (v != p && was[v] == 0) {
          dfs(v, u);
        }
    };
    dfs(0, -1);
    vector<int> val(n - 2);
    set<pair<int, int>> q;
    auto upd = [&](int u, int v) {
      if (u > v) swap(u, v);
      for (auto e : tria[{u, v}]) {
        q.erase({val[e], e});
        q.insert({++val[e], e});
      }
    };
    for (int v : order) cout << v + 1 << ' ';
    cout << "\n";
    for (int i = 0; i < (int)(n - 2); i++) q.insert({val[i] = 0, i});
    order.push_back(order[0]);
    for (int i = 0; i < (int)(order.size() - 1); i++) {
      int a = order[i], b = order[i + 1];
      upd(a, b);
    }
    auto sz = [&](int u, int v) {
      if (u > v) swap(u, v);
      return tria[{u, v}].size();
    };
    auto mov = [&](int u, int v, int id) {
      if (u > v) swap(u, v);
      tria[{u, v}].erase(id);
      for (int e : tria[{u, v}]) {
        q.erase({val[e], e});
        q.insert({++val[e], e});
      }
    };
    while (q.size()) {
      pair<int, int> p = *q.rbegin();
      q.erase(p);
      int id = p.second;
      vector<int> x = {a[id].a, a[id].b, a[id].c};
      cout << id + 1 << ' ';
      for (int i = 0; i < (int)(3); i++) {
        int a = (x[(i + 2) % 3]), b = x[i], c = x[(i + 1) % 3];
        if (sz(a, b) == 1 && sz(b, c) == 1) {
          mov(a, c, id);
          break;
        }
      }
    }
    cout << "\n";
  }
}
