#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, vector<int> > M;
int n;
vector<int> Gv[100005];
vector<int> G[100005];
vector<int> ans2;
int vis[100005];
vector<int> ans1;
void dfsG(int u, int p) {
  for (auto v : G[u]) {
    if (v == p) continue;
    dfsG(v, u);
  }
  ans2.push_back(u);
}
void dfsGv(int u) {
  for (auto v : Gv[u]) {
    if (vis[v]) continue;
    vis[v] = 1;
    dfsGv(v);
  }
  ans1.push_back(u);
}
int main() {
  int TC;
  scanf("%d", &TC);
  while (TC--) {
    M.clear();
    ans1.clear();
    ans2.clear();
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      G[i].clear();
      Gv[i].clear();
      vis[i] = 0;
    }
    for (int i = 1; i <= n - 2; i++) {
      int a[3];
      for (int i = 0; i < 3; i++) scanf("%d", &a[i]);
      sort(a, a + 3);
      M[pair<int, int>(a[0], a[1])].push_back(i);
      M[pair<int, int>(a[1], a[2])].push_back(i);
      M[pair<int, int>(a[0], a[2])].push_back(i);
    }
    for (auto x : M) {
      auto V = x.second;
      if (V.size() == 1) {
        Gv[x.first.first].push_back(x.first.second);
        Gv[x.first.second].push_back(x.first.first);
      } else {
        G[V[0]].push_back(V[1]);
        G[V[1]].push_back(V[0]);
      }
    }
    dfsG(1, -1);
    vis[1] = 1;
    dfsGv(1);
    for (auto x : ans1) printf("%d ", x);
    printf("\n");
    for (auto x : ans2) printf("%d ", x);
    printf("\n");
  }
}
