#include <bits/stdc++.h>
using namespace std;
int TC, N, PSET[100005];
vector<int> T[100005], perm, seq;
map<int, set<int>> M;
vector<int> G[100005];
bool visit[100005];
int findSet(int x) { return x == PSET[x] ? x : PSET[x] = findSet(PSET[x]); }
void dfs(int x) {
  perm.push_back(x);
  visit[x] = 1;
  for (auto y : G[x])
    if (!visit[y]) dfs(y);
}
int main() {
  scanf("%d", &TC);
  while (TC--) {
    cerr << TC << endl;
    scanf("%d", &N);
    M.clear();
    perm.clear();
    seq.clear();
    memset(visit, 0, sizeof(visit));
    for (int i = 1; i <= N; ++i) {
      PSET[i] = i;
      G[i].clear();
      T[i].clear();
    }
    for (int i = 1; i <= N - 2; ++i) {
      int x;
      for (int j = 0; j < 3; ++j) {
        scanf("%d", &x);
        T[i].push_back(x);
        M[x].insert(i);
      }
    }
    queue<int> Q;
    for (auto pr : M)
      if (pr.second.size() == 1) Q.push(pr.first);
    while (seq.size() < N - 2) {
      assert(!Q.empty());
      auto x = Q.front();
      Q.pop();
      assert(M[x].size() == 1);
      int s = *M[x].begin();
      seq.push_back(s);
      for (auto y : T[s])
        if (y != x) {
          M[y].erase(s);
          if (M[y].size() == 1) Q.push(y);
          if (findSet(x) != findSet(y)) {
            PSET[findSet(x)] = findSet(y);
            G[x].push_back(y);
            G[y].push_back(x);
          }
        }
    }
    int st = 1;
    for (int i = 1; i <= N; ++i)
      if (G[i].size() == 1) st = i;
    dfs(st);
    for (auto x : perm) printf("%d ", x);
    printf("\n");
    for (auto x : seq) printf("%d ", x);
    printf("\n");
  }
}
