#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  out << "[";
  for (auto k : v) out << k << " ";
  out << "]"
      << "\n";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, set<T> s) {
  out << "{";
  for (auto k : s) out << k << " ";
  out << "}"
      << "\n";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, pair<T, U> p) {
  out << "[ " << p.first << " , " << p.second << " ] ";
  return out;
}
template <class T, class U>
istream& operator>>(istream& in, pair<T, U>& p) {
  in >> p.first >> p.second;
  return in;
}
void DFS(int nod, vector<bool>& vis, vector<int>& rp,
         vector<vector<int> >& graf) {
  if (vis[nod]) return;
  vis[nod] = true;
  rp.push_back(nod);
  for (auto& x : graf[nod]) DFS(x, vis, rp, graf);
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<set<int> > gs(n + 1);
    vector<vector<int> > qs(n - 2, vector<int>(3)), graf(n + 1);
    for (int i = 0; i < int(n - 2); i++) {
      for (int j = 0; j < int(3); j++) {
        cin >> qs[i][j];
        gs[qs[i][j]].insert(i);
      }
    }
    queue<int> Q;
    vector<int> rq;
    map<int, map<int, int> > adj;
    for (int i = 0; i < int(n); i++)
      if (gs[i + 1].size() == 1) Q.push(i + 1);
    while (!Q.empty()) {
      int nod = Q.front();
      Q.pop();
      for (auto x : gs[nod]) {
        rq.push_back(x + 1);
        for (auto y : qs[x]) {
          if (y != nod) {
            gs[y].erase(x);
            if (gs[y].size() == 1) Q.push(y);
          }
          for (auto z : qs[x]) adj[z][y]++;
        }
      }
    }
    for (auto& ini : adj)
      for (auto& fin : ini.second)
        if (fin.second == 1)
          graf[ini.first].push_back(fin.first),
              graf[fin.first].push_back(ini.first);
    vector<bool> vis(n + 1, false);
    vector<int> rp;
    DFS(1, vis, rp, graf);
    for (auto v : rp) cout << v << " ";
    cout << '\n';
    for (auto v : rq) cout << v << " ";
    cout << '\n';
  }
  return 0;
}
