#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace std {
template <>
struct hash<pair<int, int>> {
  size_t operator()(const pair<int, int> &x) const {
    long long P = 38923, Q = 109797901;
    return (size_t)((x.first * P + x.second) % Q);
  }
};
};  // namespace std
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
void print(T t) {
  cout << t << endl;
}
template <typename T, typename... Args>
void print(T t, Args... args) {
  cout << t << " ";
  print(args...);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  for (int _ = min((int)0, (int)t); _ < max((int)0, (int)t); _ += 1) {
    int n;
    cin >> n;
    vector<vector<int>> pieces;
    vector<set<int>> cake(n);
    queue<int> q;
    for (int i = min((int)0, (int)n - 2); i < max((int)0, (int)n - 2); i += 1) {
      int a, b, c;
      cin >> a >> b >> c;
      a--;
      b--;
      c--;
      pieces.push_back({a, b, c});
      cake[a].insert(i);
      cake[b].insert(i);
      cake[c].insert(i);
    }
    for (int i = min((int)0, (int)n); i < max((int)0, (int)n); i += 1) {
      if ((int)(cake[i]).size() == 1) q.push(i);
    }
    vector<int> eat_order;
    while ((int)(q).size()) {
      int a = q.front();
      q.pop();
      if (!(int)(cake[a]).size()) continue;
      int p = *cake[a].begin();
      for (auto &x : pieces[p]) {
        cake[x].erase(p);
        if ((int)(cake[x]).size() == 1) q.push(x);
      }
      eat_order.push_back(p);
    }
    int last = eat_order[(int)(eat_order).size() - 1];
    vector<int> lp = pieces[last];
    vector<int> l(n, -1), r(n, -1);
    l[lp[0]] = lp[2];
    l[lp[1]] = lp[0];
    l[lp[2]] = lp[1];
    r[lp[0]] = lp[1];
    r[lp[1]] = lp[2];
    r[lp[2]] = lp[0];
    for (int i = (int)(eat_order).size() - 2; i >= 0; i--) {
      vector<int> p = pieces[eat_order[i]];
      int x, y, z;
      if (l[p[0]] == -1) {
        y = p[0];
        x = p[1];
        z = p[2];
        if (l[x] == z) swap(x, z);
      } else if (l[p[1]] == -1) {
        y = p[1];
        x = p[0];
        z = p[2];
        if (l[x] == z) swap(x, z);
      } else {
        y = p[2];
        x = p[1];
        z = p[0];
        if (l[x] == z) swap(x, z);
      }
      r[x] = y;
      l[y] = x;
      r[y] = z;
      l[z] = y;
    }
    for (int i = r[0]; i != 0; i = r[i]) cout << (i + 1) << " ";
    cout << "1\n";
    for (auto &x : eat_order) cout << (x + 1) << " ";
    cout << "\n";
  }
  return 0;
}
