#include <bits/stdc++.h>
using namespace std;
void dfs_order(int u, int p, vector<vector<int>> const& v, vector<int>& order) {
  for (auto i : v[u]) {
    if (i != p) {
      dfs_order(i, u, v, order);
    }
  }
  order.push_back(u);
}
void dfs_poligon(int u, vector<bool>& bo, vector<vector<int>> const& v1,
                 vector<int>& poli) {
  if (bo[u]) return;
  bo[u] = 1;
  poli.push_back(u);
  for (auto it : v1[u]) dfs_poligon(it, bo, v1, poli);
}
int du[100000 + 7];
int n;
int pr[100007], sz;
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<vector<int>> v(n - 2, vector<int>(3));
    for (int i = 0; i < n - 2; i++) {
      for (int j = 0; j < 3; j++) {
        cin >> v[i][j];
      }
      sort(v[i].begin(), v[i].end());
    }
    map<pair<int, int>, vector<int>> mp;
    for (int i = 0; i < n - 2; i++) {
      for (int j = 0; j < 2; j++) {
        for (int k = j + 1; k < 3; k++) {
          mp[{v[i][j], v[i][k]}].push_back(i);
        }
      }
    }
    vector<vector<int>> vv(n), v1(n + 1);
    memset(du, 0, sizeof(du));
    for (auto it : mp) {
      if (it.second.size() == 2) {
        auto c = it.second;
        du[c[0]]++, du[c[1]]++;
        vv[c[0]].push_back(c[1]);
        vv[c[1]].push_back(c[0]);
      } else {
        auto c = it.first;
        v1[c.first].push_back(c.second);
        v1[c.second].push_back(c.first);
      }
    }
    vector<int> order, poligon;
    dfs_order(0, -1, vv, order);
    vector<bool> bo(n + 1);
    for (int i = 0; i <= n; i++) bo[i] = 0;
    dfs_poligon(1, bo, v1, poligon);
    for (auto it : poligon) cout << it << " ";
    cout << endl;
    sz = 0;
    queue<int> q;
    int len = n - 2;
    for (int i = 0; i < len; i++) {
      if (du[i] == 1) q.push(i);
    }
    if (q.empty()) pr[++sz] = 0;
    while (!q.empty()) {
      int tp = q.front();
      pr[++sz] = tp;
      q.pop();
      for (auto x : vv[tp]) {
        du[x]--;
        if (du[x] == 1) q.push(x);
      }
    }
    for (int i = 1; i <= sz; i++) cout << pr[i] + 1 << " ";
    cout << endl;
  }
}
