#include <bits/stdc++.h>
using namespace std;
struct triangle {
  int a, b, c;
} v[100000 + 5];
int n, edges;
int mext[100000 + 5], uz[100000 + 5];
map<pair<int, int>, int> repr;
vector<int> belong[3 * 100000 + 5];
vector<int> ad[100000 + 5];
queue<int> t2ext;
pair<int, int> muchii[3 * 100000 + 5];
void new_edge(int a, int b, int id) {
  if (a > b) swap(a, b);
  pair<int, int> p = {a, b};
  if (repr.find(p) == repr.end()) {
    repr[p] = ++edges;
    muchii[edges] = {a, b};
  }
  belong[repr[p]].push_back(id);
}
void solve() {
  scanf("%d", &n);
  repr.clear();
  for (int i = 0; i <= edges; i++) belong[i].clear();
  edges = 0;
  for (int i = 1; i <= n; i++) {
    mext[i] = uz[i] = 0;
    ad[i].clear();
  }
  for (int i = 1; i <= n - 2; i++) {
    scanf("%d %d %d", &v[i].a, &v[i].b, &v[i].c);
    new_edge(v[i].a, v[i].b, i);
    new_edge(v[i].b, v[i].c, i);
    new_edge(v[i].c, v[i].a, i);
  }
  if (n == 3) {
    printf("1 2 3\n1\n");
    return;
  }
  for (int i = 1; i <= edges; i++)
    if (belong[i].size() == 1) {
      int id = belong[i][0], nod1, nod2;
      nod1 = muchii[i].first;
      nod2 = muchii[i].second;
      ad[nod1].push_back(nod2);
      ad[nod2].push_back(nod1);
      mext[id]++;
      if (mext[id] == 2) t2ext.push(id);
    }
  vector<int> ans2;
  while (!t2ext.empty()) {
    int id = t2ext.front();
    t2ext.pop();
    ans2.push_back(id);
    for (pair<int, int> p :
         {make_pair(v[id].a, v[id].b), make_pair(v[id].c, v[id].b),
          make_pair(v[id].a, v[id].c)}) {
      if (p.first > p.second) swap(p.first, p.second);
      if (belong[repr[p]].size() == 2)
        for (int x : belong[repr[p]]) {
          if (x == id) continue;
          mext[x]++;
          if (mext[x] == 2) t2ext.push(x);
        }
    }
  }
  int start = 1, crt;
  printf("%d ", start);
  crt = ad[start][0];
  uz[start] = uz[crt] = 1;
  n--;
  while (n) {
    printf("%d ", crt);
    for (int x : ad[crt])
      if (uz[x] == 0) {
        crt = x;
        uz[x] = 1;
      }
    n--;
  }
  printf("\n");
  for (int x : ans2) printf("%d ", x);
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t) {
    solve();
    t--;
  }
  return 0;
}
