#include <bits/stdc++.h>
using namespace std;
int freq[100100];
map<pair<int, int>, set<tuple<int, int, int>>> mapa;
map<tuple<int, int, int>, int> getId;
void erase(tuple<int, int, int> t) {
  int a, b, c;
  tie(a, b, c) = t;
  mapa[{a, b}].erase(t);
  mapa[{b, a}].erase(t);
  mapa[{a, c}].erase(t);
  mapa[{c, a}].erase(t);
  mapa[{b, c}].erase(t);
  mapa[{c, b}].erase(t);
}
vector<int> go(int a, int b, vector<int> &q) {
  if (mapa[{a, b}].empty()) return vector<int>();
  tuple<int, int, int> t = *(mapa[{a, b}].begin());
  vector<int> v = {get<0>(t), get<1>(t), get<2>(t)};
  erase(t);
  for (int x : v) {
    if (x != a and x != b) {
      vector<int> v1 = go(x, b, q);
      vector<int> v2 = go(a, x, q);
      q.push_back(getId[t]);
      v1.push_back(x);
      v1.insert(v1.end(), v2.begin(), v2.end());
      return v1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int n, a, b, c;
    cin >> n;
    mapa.clear();
    getId.clear();
    for (int i = int(0); i < int(n + 1); ++i) freq[i] = 0;
    vector<tuple<int, int, int>> vec(n - 2);
    for (int i = 0; i < n - 2; ++i) {
      cin >> a >> b >> c;
      tuple<int, int, int> t = make_tuple(a, b, c);
      vec[i] = t;
      getId[t] = i + 1;
      freq[a]++;
      freq[b]++;
      freq[c]++;
      mapa[{a, b}].insert(t);
      mapa[{b, a}].insert(t);
      mapa[{a, c}].insert(t);
      mapa[{c, a}].insert(t);
      mapa[{b, c}].insert(t);
      mapa[{c, b}].insert(t);
    }
    int u = 1;
    while (freq[u] != 1) u++;
    tuple<int, int, int> ini;
    for (tuple<int, int, int> tup : vec) {
      tie(a, b, c) = tup;
      if (a == u or b == u or c == u) {
        ini = tup;
        break;
      }
    }
    erase(ini);
    vector<int> p = {get<0>(ini), get<1>(ini), get<2>(ini)};
    vector<int> q = {getId[ini]};
    while (p[1] != u) {
      p.push_back(p[0]);
      p.erase(p.begin());
    }
    vector<int> ans = go(p[0], p[2], q);
    p.insert(p.end(), ans.begin(), ans.end());
    for (int x : p) cout << x << " \n"[x == p.back()];
    for (int x : q) cout << x << " \n"[x == q.back()];
  }
  return 0;
}
