#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 10;
inline int read() {
  int r = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = getchar();
  return r;
}
struct edge {
  int x, y;
  edge() {}
  edge(int a, int b) {
    x = min(a, b);
    y = max(a, b);
  }
} fs[N];
inline bool operator<(const edge &a, const edge &b) {
  return a.x == b.x ? a.y < b.y : a.x < b.x;
}
inline bool operator==(const edge &a, const edge &b) {
  return a.x == b.x && a.y == b.y;
}
map<edge, int> mp;
int cnt;
vector<int> v[N], p[N];
int T, n;
struct redge {
  int next, to;
} e[N << 1], c[N << 1];
int head[N], sum, headc[N], sumc, ind[N];
inline void add(int x, int y, redge *e, int *head, int &sum) {
  e[++sum].next = head[x];
  head[x] = sum;
  e[sum].to = y;
  ++ind[y];
}
int emp[N][2];
bool vis[N];
void DFS(int now) {
  printf("test:%d\n", now);
  vis[now] = 1;
  for (int i = head[now]; i; i = e[i].next) {
    int to = e[i].to;
    if (vis[to]) continue;
    add(now, to, c, headc, sumc);
    DFS(to);
  }
  return;
}
int st[N], top;
void DFS2(int now) {
  vis[now] = 1;
  st[++top] = now;
  for (int i = 0; i < 2; i++) {
    edge o = fs[emp[now][i]];
    int to;
    if (o.x == now)
      to = o.y;
    else
      to = o.x;
    if (vis[to]) continue;
    DFS2(to);
  }
  return;
}
int q[N], ans[N], ss;
void Topo() {
  int head = 1, tail = 0;
  ss = 0;
  if (n == 3) {
    ans[++ss] = 1;
    return;
  }
  for (int i = 1; i <= n - 2; i++)
    if (ind[i] == 1) q[++tail] = i;
  while (head <= tail) {
    int now = q[head++];
    ans[++ss] = now;
    for (int i = ::head[now]; i; i = e[i].next) {
      int to = e[i].to;
      --ind[to];
      if (ind[to] == 1) q[++tail] = to;
    }
  }
}
int main() {
  T = read();
  while (T--) {
    mp.clear();
    for (int i = 1; i <= cnt; i++) v[i].clear();
    cnt = 0;
    n = read();
    for (int i = 1; i <= n - 2; i++) {
      int x = read(), y = read(), z = read();
      if (mp.find(edge(x, y)) == mp.end()) {
        mp[edge(x, y)] = ++cnt;
        p[x].push_back(cnt);
        p[y].push_back(cnt);
        fs[cnt] = edge(x, y);
      }
      v[mp[edge(x, y)]].push_back(i);
      if (mp.find(edge(y, z)) == mp.end()) {
        mp[edge(y, z)] = ++cnt;
        p[y].push_back(cnt);
        p[z].push_back(cnt);
        fs[cnt] = edge(y, z);
      }
      v[mp[edge(y, z)]].push_back(i);
      if (mp.find(edge(x, z)) == mp.end()) {
        mp[edge(x, z)] = ++cnt;
        p[x].push_back(cnt);
        p[z].push_back(cnt);
        fs[cnt] = edge(x, z);
      }
      v[mp[edge(x, z)]].push_back(i);
    }
    for (int i = 1; i <= cnt; i++) {
      if (v[i].size() == 1) continue;
      add(v[i][0], v[i][1], e, head, sum);
      add(v[i][1], v[i][0], e, head, sum);
    }
    for (int i = 1; i <= n; i++) {
      int ns = 0;
      for (auto j = p[i].begin(); j != p[i].end(); j++) {
        if (v[(*j)].size() == 1) emp[i][ns++] = (*j);
      }
    }
    top = 0;
    for (int i = 1; i <= n; i++) vis[i] = 0;
    DFS2(1);
    for (int i = 1; i <= top; i++) printf("%d ", st[i]);
    printf("\n");
    Topo();
    for (int i = 1; i <= ss; i++) printf("%d ", ans[i]);
    printf("\n");
    for (int i = 1; i <= n; i++) p[i].clear(), head[i] = 0, headc[i] = 0;
    sum = sumc = 0;
  }
  return 0;
}
