#include <bits/stdc++.h>
using namespace std;
void dfs0(long long src, long long par, vector<long long> &p,
          vector<vector<long long> > &g, int idx) {
  if (idx == p.size()) return;
  p[idx++] = src;
  for (long long neigh : g[src]) {
    if (neigh != par) {
      dfs0(neigh, src, p, g, idx);
    }
  }
}
void dfs1(long long src, long long par, vector<long long> &p,
          vector<vector<long long> > &g, int &idx) {
  for (long long neigh : g[src]) {
    if (neigh != par) {
      dfs1(neigh, src, p, g, idx);
    }
  }
  p[idx++] = src;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<vector<long long> > v(n - 2, vector<long long>(3));
    for (int i = 0; i < n - 2; i++) {
      cin >> v[i][0] >> v[i][1] >> v[i][2];
      v[i][0]--;
      v[i][1]--;
      v[i][2]--;
      sort(v[i].begin(), v[i].end());
    }
    map<pair<long long, long long>, vector<long long> > m;
    for (int i = 0; i < n - 2; i++) {
      m[{v[i][0], v[i][1]}].push_back(i);
      m[{v[i][1], v[i][2]}].push_back(i);
      m[{v[i][0], v[i][2]}].push_back(i);
    }
    vector<vector<long long> > g(n);
    set<pair<long long, long long> > outerEdges;
    vector<vector<long long> > gfaces(n - 2);
    for (auto it : m) {
      if (it.second.size() == 1) {
        g[it.first.first].push_back(it.first.second);
        g[it.first.second].push_back(it.first.first);
        outerEdges.insert(it.first);
      } else {
        gfaces[it.second[0]].push_back(it.second[1]);
        gfaces[it.second[1]].push_back(it.second[0]);
      }
    }
    vector<long long> p(n);
    dfs0(0, 0, p, g, 0);
    vector<long long> forder(n - 2);
    int idx = 0;
    dfs1(0, 0, forder, gfaces, idx);
    for (int i = 0; i < n; i++) {
      if (i == 0)
        cout << p[i] + 1;
      else
        cout << " " << p[i] + 1;
    }
    cout << endl;
    for (int i = 0; i < n - 2; i++) {
      if (i == 0)
        cout << forder[i] + 1;
      else
        cout << " " << forder[i] + 1;
    }
    cout << endl;
  }
  return 0;
}
