#include <bits/stdc++.h>
using namespace std;
const int max_n = 100005;
int T, n;
vector<vector<int>> a;
map<pair<int, int>, int> mp;
int nid;
int gid(pair<int, int> p) {
  if (mp.count(p)) return mp[p];
  return mp[p] = nid++;
}
vector<int> G[max_n * 2], g[max_n];
int in[max_n];
int q[max_n], tot = 0, ord[max_n];
int nex[max_n];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    a.resize(n);
    for (int i = 0; i < n - 2; i++) {
      a[i].resize(3);
      for (int j = 0; j < 3; j++) scanf("%d", &a[i][j]);
    }
    nid = 0;
    mp.clear();
    for (int i = 0; i < n * 2 - 3; i++) G[i].clear();
    for (int i = 0; i < n; i++) g[i].clear();
    for (int i = 0; i < n - 2; i++) {
      for (int j = 0; j < 3; j++) {
        int x = a[i][j], y = a[i][(j + 1) % 3];
        if (x > y) swap(x, y);
        G[gid(pair<int, int>(x, y))].push_back(i);
      }
    }
    for (int i = 0; i < n; i++) in[i] = 0;
    for (int i = 0; i < nid; i++) {
      if (G[i].size() == 1) continue;
      int x = G[i][0], y = G[i][1];
      g[x].push_back(y);
      g[y].push_back(x);
      in[x]++, in[y]++;
    }
    queue<int> que;
    for (int i = 0; i < n - 2; i++) {
      if (in[i] == 1 || in[i] == 0) {
        que.push(i);
      }
    }
    tot = 0;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      q[++tot] = u;
      for (auto v : g[u]) {
        in[v]--;
        if (in[v] == 1) {
          que.push(v);
        }
      }
    }
    for (int i = 1; i <= n; i++) nex[i] = -1;
    for (int i = tot; i >= 1; i--) {
      int u = q[i];
      int x = a[u][0], y = a[u][1], z = a[u][2];
      if (i == tot) {
        nex[x] = y, nex[y] = z, nex[z] = x;
      } else {
        if (nex[x] == -1) swap(x, z);
        if (nex[y] == -1) swap(y, z);
        if (nex[x] != y) swap(x, y);
        nex[x] = z, nex[z] = y;
      }
    }
    int now = 1;
    while (1) {
      printf("%d ", now);
      now = nex[now];
      if (now == 1) break;
    }
    printf("\n");
    for (int i = 1; i <= tot; i++) printf("%d ", q[i] + 1);
    printf("\n");
  }
  return 0;
}
