#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10, MAXM = 2e6 + 10;
const int INF = INT_MAX, SINF = 0x3f3f3f3f;
const long long llINF = LLONG_MAX;
const int MOD = 1e9 + 7, mod = 998244353;
queue<int> q;
int n, du[MAXN];
int vis[MAXN];
vector<int> ans[MAXN], ans2;
int fa[MAXN];
int _find(int x) { return fa[x] ^ x ? fa[x] = _find(fa[x]) : fa[x]; }
struct Node {
  int a[4], id;
};
vector<Node> g[MAXN];
int ddddd[MAXN];
void dfs(int u) {
  vis[u] = 1;
  printf("%d ", u);
  for (auto j : ans[u]) {
    if (!vis[j]) dfs(j);
  }
}
void solve() {
  while (!q.empty()) q.pop();
  scanf("%d", &n);
  memset(vis, 0, (n + 5) * sizeof(int));
  memset(du, 0, (n + 5) * sizeof(int));
  memset(ddddd, 0, (n + 5) * sizeof(int));
  for (int i = 1; i <= n; i++) g[i].resize(0);
  for (int i = 1; i <= n; i++) ans[i].resize(0);
  for (int i = 1; i <= n; i++) fa[i] = i;
  ans2.resize(0);
  for (int i = 1; i <= n - 2; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    du[u]++;
    du[v]++;
    du[w]++;
    Node tmp;
    tmp.a[0] = u;
    tmp.a[1] = v;
    tmp.a[2] = w;
    tmp.id = i;
    g[u].push_back(tmp);
    g[v].push_back(tmp);
    g[w].push_back(tmp);
  }
  for (int i = 1; i <= n; i++)
    if (du[i] == 1) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto z : g[u]) {
      if (vis[z.id]) continue;
      vis[z.id] = 1;
      ans2.push_back(z.id);
      for (int i = 0; i < 3; i++) {
        du[z.a[i]]--;
        if (du[z.a[i]] == 1) q.push(z.a[i]);
        if (u == z.a[i]) continue;
        int p = _find(u), v = _find(z.a[i]);
        if (p != v) {
          ddddd[u]++;
          ddddd[z.a[i]]++;
          ans[u].push_back(z.a[i]);
          ans[z.a[i]].push_back(u);
          fa[p] = v;
        }
      }
    }
  }
  vector<int> qqqqq;
  for (int i = 1; i <= n; i++)
    if (ddddd[i] == 1) qqqqq.push_back(i);
  ans[qqqqq[0]].push_back(qqqqq[1]);
  ans[qqqqq[1]].push_back(qqqqq[0]);
  memset(vis, 0, (n + 5) * sizeof(int));
  dfs(1);
  puts("");
  for (auto j : ans2) printf("%d ", j);
  puts("");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
