#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
using pi = pair<int, int>;
void solve() {
  int n;
  scanf(" %d", &n);
  map<pi, vector<int>> edge;
  vector<vector<int>> tri(n - 2);
  for (int i = 0; i < (int)(n - 2); ++i) {
    vector<int> t(3);
    for (int j = 0; j < (int)(3); ++j) {
      scanf(" %d", &t[j]);
      --t[j];
    }
    for (int j = 0; j < (int)(3); ++j) {
      int u = t[j], v = t[(j + 1) % 3];
      if (u > v) swap(u, v);
      edge[{u, v}].push_back(i);
    }
    tri[i] = t;
  }
  vector<vector<int>> G(n);
  for (const auto& p : edge) {
    if (p.second.size() == 2) {
      int u = p.second[0], v = p.second[1];
      G[u].push_back(v);
      G[v].push_back(u);
    }
  }
  vector<int> d(n - 2, n);
  d[0] = 0;
  queue<int> que({0});
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int e : G[v]) {
      if (d[e] > d[v] + 1) {
        d[e] = d[v] + 1;
        que.push(e);
      }
    }
  }
  vector<pi> qq(n - 2);
  for (int i = 0; i < (int)(n - 2); ++i) qq[i] = {d[i], i};
  sort((qq).begin(), (qq).end(), greater<pi>());
  vector<int> q(n - 2);
  for (int i = 0; i < (int)(n - 2); ++i) q[i] = qq[i].second;
  vector<bool> used(n);
  vector<set<int>> nxt(n);
  vector<int> start = tri[q[n - 3]];
  for (int i = 0; i < (int)(3); ++i) {
    used[start[i]] = true;
    for (int j = 0; j < (int)(3); ++j)
      if (i != j) nxt[start[i]].insert(start[j]);
  }
  for (int i = n - 4; i >= 0; --i) {
    vector<int> t = tri[q[i]];
    int idx = -1;
    for (int j = 0; j < (int)(3); ++j)
      if (!used[t[j]]) idx = j;
    assert(idx != -1);
    int v = t[idx];
    used[v] = true;
    vector<int> o;
    for (int j = 0; j < (int)(3); ++j)
      if (j != idx) o.push_back(t[j]);
    for (int j = 0; j < (int)(2); ++j) {
      nxt[v].insert(o[j]);
      nxt[o[j]].insert(v);
      nxt[o[j]].erase(o[!j]);
    }
  }
  int pre = -1;
  int now = 0;
  vector<int> p(n);
  for (int i = 0; i < (int)(n); ++i) {
    p[i] = now;
    for (int j : nxt[now])
      if (pre != j) {
        pre = now;
        now = j;
        break;
      }
  }
  for (int i = 0; i < (int)(n); ++i)
    printf("%d%c", p[i] + 1, " \n"[i == n - 1]);
  for (int i = 0; i < (int)(n - 2); ++i)
    printf("%d%c", q[i] + 1, " \n"[i == n - 3]);
}
int main() {
  int T;
  scanf(" %d", &T);
  while (T--) solve();
  return 0;
}
