#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
struct Data {
  int a, b, c;
} d[N + 5];
vector<int> trg[N + 5], ans2, G[N + 5];
int dgr[N + 5];
bool vis[N + 5];
int fa[N + 5];
inline int ffind(int x) { return x == fa[x] ? fa[x] : fa[x] = ffind(fa[x]); }
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    memset(dgr, 0, (n + 4) * sizeof(int));
    memset(vis, false, (n + 4) * sizeof(bool));
    for (int i = 1; i <= n; ++i) {
      trg[i].clear();
      G[i].clear();
      fa[i] = i;
    }
    ans2.clear();
    for (int i = 1; i <= n - 2; ++i) {
      scanf("%d %d %d", &d[i].a, &d[i].b, &d[i].c);
      ++dgr[d[i].a];
      ++dgr[d[i].b];
      ++dgr[d[i].c];
      trg[d[i].a].push_back(i);
      trg[d[i].b].push_back(i);
      trg[d[i].c].push_back(i);
    }
    queue<int> Q;
    for (int i = 1; i <= n; ++i) {
      if (dgr[i] == 1) Q.push(i);
    }
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int &it : trg[u]) {
        if (!vis[it]) {
          vis[it] = true;
          ans2.push_back(it);
          if (d[it].a != u) {
            if (--dgr[d[it].a] == 1) Q.push(d[it].a);
            if (ffind(u) != ffind(d[it].a)) {
              fa[ffind(d[it].a)] = ffind(u);
              G[u].push_back(d[it].a);
              G[d[it].a].push_back(u);
            }
          }
          if (d[it].b != u) {
            if (--dgr[d[it].b] == 1) Q.push(d[it].b);
            if (ffind(u) != ffind(d[it].b)) {
              fa[ffind(d[it].b)] = ffind(u);
              G[u].push_back(d[it].b);
              G[d[it].b].push_back(u);
            }
          }
          if (d[it].c != u) {
            if (--dgr[d[it].c] == 1) Q.push(d[it].c);
            if (ffind(u) != ffind(d[it].c)) {
              fa[ffind(d[it].c)] = ffind(u);
              G[u].push_back(d[it].c);
              G[d[it].c].push_back(u);
            }
          }
        }
      }
    }
    deque<int> ans1;
    ans1.push_back(1);
    int u1 = G[1][0], u2 = 0, _fa = 1;
    if (G[1].size() > 1) u2 = G[1][1];
    ans1.push_back(u1);
    while (G[u1].size() > 1) {
      if (G[u1][0] != _fa) {
        _fa = u1;
        u1 = G[u1][0];
      } else {
        _fa = u1;
        u1 = G[u1][1];
      }
      ans1.push_back(u1);
    }
    if (u2) {
      ans1.push_front(u2);
      _fa = 1;
      while (G[u2].size() > 1) {
        if (G[u2][0] != _fa) {
          _fa = u2;
          u2 = G[u2][0];
        } else {
          _fa = u2;
          u2 = G[u2][1];
        }
        ans1.push_front(u2);
      }
    }
    while (!ans1.empty()) {
      printf("%d ", ans1.front());
      ans1.pop_front();
    }
    printf("\n");
    for (int &it : ans2) printf("%d ", it);
    printf("\n");
  }
  return 0;
}
