#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &u) {
  u = 0;
  char c = getchar();
  int flag = 0;
  while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    u = (u << 3) + (u << 1) + (c ^ 48), c = getchar();
  if (flag) u = -u;
}
template <class T>
void write(T u) {
  if (u < 0) printf("-"), u = -u;
  if (u < 10)
    putchar(48 + u);
  else
    write(u / 10), putchar(48 + u % 10);
}
void write(char u) { putchar(u); }
template <class T, class... Arg>
void read(T &u, Arg &...v) {
  read(u);
  read(v...);
}
template <class T, class... Arg>
void write(T u, Arg... v) {
  write(u);
  write(v...);
}
template <class T>
bool checkmin(T &a, T b) {
  return (b < a ? a = b, 1 : 0);
}
template <class T>
bool checkmax(T &a, T b) {
  return (b > a ? a = b, 1 : 0);
}
template <class T>
T _min(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
T _max(T a, T b) {
  return (a > b ? a : b);
}
const int N = 200005;
int n, a[N][3], vis[N], deg[N], total = 0;
map<pair<int, int>, int> cnt, mp;
map<pair<int, int>, int>::iterator it;
vector<int> G[N], H[N];
void add_edge(int u, int v) {
  G[u].push_back(v);
  ++deg[v];
}
void add_edge2(int u, int v) { H[u].push_back(v); }
void add(int u, int v, int w) {
  pair<int, int> P = make_pair(u, v);
  int t = mp[P];
  cnt[P]++;
  if (t) {
    add_edge(t, w);
    add_edge(w, t);
  }
  mp[P] = w;
}
void init() {
  read(n);
  cnt.clear();
  mp.clear();
  total = 0;
  for (int i = 1; i <= n; ++i) {
    G[i].clear();
    H[i].clear();
    deg[i] = vis[i] = 0;
  }
  for (int i = 1; i <= n - 2; ++i) {
    for (int j = 0; j <= 2; ++j) {
      read(a[i][j]);
    }
    sort(a[i], a[i] + 3);
    add(a[i][0], a[i][1], i);
    add(a[i][0], a[i][2], i);
    add(a[i][1], a[i][2], i);
  }
}
void dfs(int x, int f) {
  if (vis[x]) return;
  vis[x] = 1;
  ++total;
  write(x, " \n"[total == n]);
  for (int i = 0; i < (int)H[x].size(); ++i) {
    int to = H[x][i];
    if (to == f) continue;
    dfs(to, x);
  }
}
void get_P() {
  for (it = cnt.begin(); it != cnt.end(); ++it) {
    if (it->second == 1) {
      add_edge2(it->first.first, it->first.second);
      add_edge2(it->first.second, it->first.first);
    }
  }
  dfs(1, 0);
}
void get_Q() {
  queue<int> q;
  total = 0;
  for (int i = 1; i <= n - 2; ++i) vis[i] = 0;
  for (int i = 1; i <= n - 2; ++i) {
    if (deg[i] <= 1) {
      q.push(i);
    }
  }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    ++total;
    write(now, " \n"[total == n - 2]);
    vis[now] = 1;
    for (int i = 0; i < (int)G[now].size(); ++i) {
      int to = G[now][i];
      if (vis[to]) continue;
      --deg[to];
      if (deg[to] == 1) {
        q.push(to);
      }
    }
  }
}
void solve() {
  get_P();
  get_Q();
}
int main() {
  int T = 1;
  read(T);
  while (T--) {
    init();
    solve();
  }
  return 0;
}
