#include <bits/stdc++.h>
using namespace std;
class DebugStream {
} LOG;
template <typename T>
DebugStream &operator<<(DebugStream &s, const T &) {
  return s;
}
mt19937 rnd(time(NULL));
const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20,
          bs = 29;
set<int> adj[maxN], cta[maxN];
int n, inpu[maxN][3];
pair<long long, long long> clean(pair<long long, long long> x) {
  if (x.first > x.second) swap(x.first, x.second);
  return x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) cta[i].clear(), adj[i].clear();
    map<pair<long long, long long>, int> mp;
    for (int i = 0; i < n - 2; i++) {
      int a[3];
      for (int j = 0; j < 3; j++) {
        cin >> a[j], a[j]--;
        cta[a[j]].insert(i);
      }
      for (int j = 0; j < 3; j++)
        for (int k = j + 1; k < 3; k++)
          mp[clean(pair<long long, long long>(a[j], a[k]))]++;
      memcpy(inpu[i], a, sizeof inpu[i]);
    }
    for (auto el : mp)
      if (el.second == 1)
        adj[el.first.first].insert(el.first.second),
            adj[el.first.second].insert(el.first.first);
    for (int i = 0, prv = 0; i < n; i++) {
      cout << prv + 1 << ' ';
      adj[*adj[prv].begin()].erase(prv);
      if (adj[prv].size()) prv = *adj[prv].begin();
    }
    cout << '\n';
    set<pair<long long, long long> > mys;
    for (int i = 0; i < n; i++)
      mys.insert(pair<long long, long long>(cta[i].size(), i));
    for (int i = 0; i < n - 2; i++) {
      auto cr = *cta[mys.begin()->second].begin();
      cout << cr + 1 << ' ';
      for (int j = 0; j < 3; j++) {
        int tored = inpu[cr][j];
        mys.erase(pair<long long, long long>(cta[tored].size(), tored));
        cta[tored].erase(cr);
        mys.insert(pair<long long, long long>(cta[tored].size(), tored));
      }
      while (mys.size() && mys.begin()->first == 0) mys.erase(mys.begin());
    }
    cout << '\n';
  }
}
