#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &r) {
  static char c;
  r = 0;
  int f = 1;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9';
       r = (r << 1) + (r << 3) + (c ^ 48), c = getchar())
    ;
  r *= f;
}
const int N = 1e5 + 105;
int n, a[N][4], vis[N];
vector<int> to[N];
void solve() {
  map<pair<int, int>, int> ma;
  map<pair<int, int>, vector<int>> mb;
  cin >> n;
  for (int i = 1; i < (int)n + 1; ++i) vis[i] = 0, to[i].clear();
  for (int i = 1; i < (int)n - 1; ++i) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
    sort(a[i], a[i] + 3);
    pair<int, int> p1 = make_pair(a[i][0], a[i][1]);
    pair<int, int> p2 = make_pair(a[i][0], a[i][2]);
    pair<int, int> p3 = make_pair(a[i][1], a[i][2]);
    ma[p1]++, ma[p2]++, ma[p3]++;
    mb[p1].push_back(i), mb[p2].push_back(i), mb[p3].push_back(i);
  }
  if (n == 3) {
    cout << "1 2 3" << '\n' << 1 << '\n';
    return;
  }
  vector<int> v, v2;
  pair<int, int> sta;
  for (auto it : ma) {
    if (it.second == 1) {
      to[it.first.first].push_back(it.first.second);
      to[it.first.second].push_back(it.first.first);
      sta = it.first;
    }
  }
  int idx = 1;
  vis[1] = 1;
  for (;;) {
    v.push_back(idx);
    int f = 0;
    for (auto i : to[idx]) {
      if (!vis[i]) {
        vis[i] = 1;
        f = 1;
        idx = i;
        break;
      }
    }
    if (!f) break;
  }
  for (int i = 1; i < (int)n + 1; ++i) vis[i] = 0;
  queue<pair<int, int>> que;
  que.push(sta);
  while (!que.empty()) {
    pair<int, int> now = que.front();
    que.pop();
    int t;
    for (auto it : mb[now]) {
      if (vis[it]) continue;
      t = it;
      break;
    }
    v2.push_back(t);
    vis[t] = 1;
    pair<int, int> p1 = make_pair(a[t][0], a[t][1]);
    pair<int, int> p2 = make_pair(a[t][0], a[t][2]);
    pair<int, int> p3 = make_pair(a[t][1], a[t][2]);
    ma[p1]--;
    if (ma[p1] == 1) que.push(p1);
    ma[p2]--;
    if (ma[p2] == 1) que.push(p2);
    ma[p3]--;
    if (ma[p3] == 1) que.push(p3);
  }
  for (auto i : v) cout << i << " ";
  cout << '\n';
  for (int i = n - 3; i >= 0; --i) cout << v2[i] << " ";
  cout << '\n';
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
