#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<pair<int, int>, int> cnt;
    map<int, set<int>> present;
    map<int, set<int>> poly;
    int p[n - 1], q[n - 1], r[n - 1];
    for (int i = int(1); i <= int(n - 2); i++) {
      cin >> p[i] >> q[i] >> r[i];
      int x = p[i];
      int y = q[i];
      int z = r[i];
      if (y > z) swap(y, z);
      if (x > y) swap(x, y);
      if (y > z) swap(y, z);
      cnt[make_pair(x, y)]++;
      cnt[make_pair(x, z)]++;
      cnt[make_pair(y, z)]++;
      poly[x].insert(i);
      poly[y].insert(i);
      poly[z].insert(i);
    }
    for (auto it : poly) present[(it.second).size()].insert(it.first);
    int ans[n + 1];
    vector<int> adj[n + 1];
    for (auto it : cnt) {
      if (it.second == 1) {
        adj[it.first.first].push_back(it.first.second);
        adj[it.first.second].push_back(it.first.first);
      }
    }
    int prev = -1;
    int pos = 1;
    for (int i = int(1); i <= int(n); i++) {
      ans[i] = pos;
      int temp = pos;
      if (i == n) break;
      if (adj[pos][0] != prev)
        pos = adj[pos][0];
      else
        pos = adj[pos][1];
      prev = temp;
    }
    for (int i = int(1); i <= int(n); i++) cout << ans[i] << " ";
    cout << "\n";
    int ct = n - 2;
    while (ct) {
      auto it = present[1].begin();
      int y = (*it);
      int x = (*poly[y].begin());
      cout << x << " ";
      int sz1 = poly[p[x]].size();
      int sz2 = poly[q[x]].size();
      int sz3 = poly[r[x]].size();
      poly[p[x]].erase(x);
      poly[q[x]].erase(x);
      poly[r[x]].erase(x);
      present[sz1].erase(p[x]);
      present[sz2].erase(q[x]);
      present[sz3].erase(r[x]);
      if (sz1 > 1) present[sz1 - 1].insert(p[x]);
      if (sz2 > 1) present[sz2 - 1].insert(q[x]);
      if (sz3 > 1) present[sz3 - 1].insert(r[x]);
      ct--;
    }
    cout << "\n";
  }
}
