#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e6 + 8;
const long long MOD = 1e9 + 7;
const long long sz = 1e5 + 5;
void f_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
}
long long n;
vector<long long> g[MAX];
bool vis[MAX];
void dfs(long long node, long long parent, long long cnt) {
  if (!cnt) return;
  vis[node] = true;
  cout << node << " ";
  for (auto child : g[node]) {
    if (!vis[child]) {
      dfs(child, node, cnt - 1);
    }
  }
}
void solve() {
  cin >> n;
  memset(vis, false, sizeof vis);
  for (long long i = 0; i < n + 1; i++) g[i].clear();
  vector<long long> deg(n + 1);
  set<vector<long long>> involved[n + 1];
  map<vector<long long>, long long> index;
  map<pair<long long, long long>, long long> edges;
  for (long long i = 0; i < n + 2; i++) g[i].clear();
  for (long long i = 0; i < n - 2; i++) {
    vector<long long> tri(3);
    for (auto &el : tri) cin >> el;
    sort(begin(tri), end(tri));
    for (auto el : tri) {
      deg[el]++;
      involved[el].insert(tri);
    }
    index[tri] = i + 1;
    for (long long j = 0; j < 2; j++) {
      for (long long k = j + 1; k < 3; k++) {
        edges[{tri[j], tri[k]}]++;
      }
    }
  }
  for (auto k : edges) {
    if (k.second == 1) {
      auto ed = k.first;
      g[ed.first].push_back(ed.second);
      g[ed.second].push_back(ed.first);
    }
  }
  dfs(1, -1, n);
  cout << "\n";
  set<pair<long long, long long>> pq;
  for (long long i = 1; i < n + 1; i++) {
    pq.insert({deg[i], i});
  }
  while (pq.size()) {
    auto el = *(pq.begin());
    long long curr = el.second;
    auto triangle = *(involved[curr].begin());
    cout << index[triangle] << " ";
    pq.erase(pq.begin());
    for (auto ver : triangle) {
      if (ver != curr) {
        pq.erase({deg[ver]--, ver});
        involved[ver].erase(triangle);
      }
    }
    for (auto ver : triangle) {
      if (deg[ver] && ver != curr) {
        pq.insert({deg[ver], ver});
      }
    }
  }
  cout << "\n";
}
int32_t main() {
  f_io();
  long long tc = 1;
  cin >> tc;
  while (tc--) {
    solve();
  }
}
