#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int n;
int a[N][4];
set<int> cnt[N];
vector<int> g[N];
int used[N];
inline void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cnt[i].clear(), g[i].clear(), used[i] = 0;
  for (int i = 1; i <= n - 2; ++i) {
    for (int j = 1; j <= 3; ++j) cin >> a[i][j], cnt[a[i][j]].insert(i);
  }
  set<pair<int, int> > s;
  for (int i = 1; i <= n; ++i) s.insert({cnt[i].size(), i});
  vector<int> order;
  map<pair<int, int>, int> diag;
  pair<int, int> last_diag;
  while (!s.empty()) {
    int x = s.begin()->second;
    assert(cnt[x].size() == 1);
    int i = *cnt[x].begin();
    for (int j = 1; j <= 3; ++j) {
      if (cnt[a[i][j]].find(i) != cnt[a[i][j]].end()) {
        s.erase({cnt[a[i][j]].size(), a[i][j]});
        cnt[a[i][j]].erase(i);
        if (cnt[a[i][j]].size() > 0) {
          s.insert({cnt[a[i][j]].size(), a[i][j]});
        }
      }
      if (a[i][j] == x) {
        int nxt = (j <= 2 ? a[i][j + 1] : a[i][1]);
        int pre = (j == 1 ? a[i][3] : a[i][j - 1]);
        diag[{nxt, pre}] = diag[{pre, nxt}] = 1;
        last_diag = {nxt, pre};
        if (!diag.count({x, nxt})) g[x].push_back(nxt), g[nxt].push_back(x);
        if (!diag.count({x, pre})) g[x].push_back(pre), g[pre].push_back(x);
      }
    }
    order.push_back(i);
  }
  int v = 1;
  vector<int> perm, rev;
  while (!used[v]) {
    used[v] = 1;
    int nxt = g[v][0];
    perm.push_back(v);
    if (used[nxt] and g[v].size() > 1) nxt = g[v][1];
    v = nxt;
  }
  v = 1;
  used[v] = 0;
  while (!used[v]) {
    used[v] = 1;
    int nxt = g[v][0];
    rev.push_back(v);
    if (used[nxt] and g[v].size() > 1) nxt = g[v][1];
    v = nxt;
  }
  reverse(rev.begin(), rev.end());
  rev.pop_back();
  for (int x : perm) cout << x << ' ';
  for (int x : rev) cout << x << ' ';
  cout << '\n';
  for (int x : order) cout << x << ' ';
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
