#include <bits/stdc++.h>
using namespace std;
const int N = 555555;
int tc, n, m;
int a[N][3];
map<pair<int, int>, vector<int> > tr;
vector<int> ansp, anst, fp, ft;
void addp(int x) {
  if (!fp[x]) {
    fp[x] = 1;
    ansp.push_back(x);
  }
}
int gettr(int tid, int x, int y) {
  if (x > y) {
    swap(x, y);
  }
  vector<int>& trlist = tr[make_pair(x, y)];
  for (int i = 0; i < trlist.size(); i++) {
    if (trlist[i] != tid && !ft[trlist[i]]) {
      return trlist[i];
    }
  }
  return -1;
}
int getp(int tid, int x, int y) {
  for (int i = 0; i < 3; i++) {
    if (a[tid][i] != x && a[tid][i] != y) {
      return a[tid][i];
    }
  }
  return -1;
}
void dfs(int tid, int x, int y, int z) {
  ft[tid] = 1;
  addp(x);
  int t1 = gettr(tid, x, y);
  if (t1 != -1) {
    int w = getp(t1, x, y);
    dfs(t1, x, w, y);
  }
  addp(y);
  int t2 = gettr(tid, y, z);
  if (t2 != -1) {
    int w = getp(t2, y, z);
    dfs(t2, y, w, z);
  }
  addp(z);
  anst.push_back(tid);
  int t3 = gettr(tid, z, x);
  if (t3 != -1) {
    int w = getp(t3, z, x);
    dfs(t3, z, w, x);
  }
}
int main() {
  scanf("%d", &tc);
  while (tc--) {
    tr.clear();
    ansp.clear();
    anst.clear();
    scanf("%d", &n);
    fp = vector<int>(n + 1, 0);
    ft = vector<int>(n, 0);
    for (int i = 1; i <= n - 2; i++) {
      scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
      sort(a[i], a[i] + 3);
      tr[make_pair(a[i][0], a[i][1])].push_back(i);
      tr[make_pair(a[i][0], a[i][2])].push_back(i);
      tr[make_pair(a[i][1], a[i][2])].push_back(i);
    }
    dfs(1, a[1][0], a[1][1], a[1][2]);
    for (int i = 0; i < ansp.size(); i++) {
      printf("%d%c", ansp[i], i + 1 == ansp.size() ? '\n' : ' ');
    }
    for (int i = 0; i < anst.size(); i++) {
      printf("%d%c", anst[i], i + 1 == anst.size() ? '\n' : ' ');
    }
  }
  return 0;
}
