#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
bool used[maxn];
void dfs(int k, vector<vector<int>> &v, int move) {
  if (!used[k]) {
    used[k] = true;
    for (int l : v[k]) {
      dfs(l, v, move);
    }
    cout << k + move << " ";
  }
}
pair<int, int> f(pair<int, int> p) {
  if (p.first < p.second) {
    int tmp = p.first;
    p.first = p.second;
    p.second = tmp;
  }
  return p;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<pair<int, int>, vector<int>> segs;
    for (int i = 0; i < n - 2; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      segs[f({a, b})].push_back(i);
      segs[f({b, c})].push_back(i);
      segs[f({a, c})].push_back(i);
    }
    vector<vector<int>> pol(maxn);
    vector<vector<int>> tree(maxn);
    for (auto m : segs) {
      if (m.second.size() == 1) {
        pol[m.first.first].push_back(m.first.second);
        pol[m.first.second].push_back(m.first.first);
      } else {
        tree[m.second[0]].push_back(m.second[1]);
        tree[m.second[1]].push_back(m.second[0]);
      }
    }
    for (int i = 0; i <= n; i++) used[i] = false;
    dfs(1, pol, 0);
    cout << "\n";
    for (int i = 0; i <= n; i++) used[i] = false;
    dfs(0, tree, 1);
    cout << "\n";
  }
  return 0;
}
