#include <bits/stdc++.h>
using namespace std;
void dfs(int ac, vector<vector<int> > &ad, vector<int> &vi) {
  cout << (ac + 1) << ' ';
  vi[ac] = 1;
  if (vi[ad[ac][0]] == 0)
    dfs(ad[ac][0], ad, vi);
  else if (vi[ad[ac][1]] == 0)
    dfs(ad[ac][1], ad, vi);
}
void up(int ac, vector<vector<pair<vector<int>, int> > > &et, vector<int> &oc,
        vector<int> &vi, priority_queue<pair<int, int> > &pq) {
  for (int i = 0; i < et[ac].size(); i++) {
    if (vi[et[ac][i].second] == 0) {
      vi[et[ac][i].second] = 1;
      for (int j = 0; j < 3; j++) {
        oc[et[ac][i].first[j] - 1]--;
        if (oc[et[ac][i].first[j] - 1] == 1) {
          pq.push(pair<int, int>(-1, et[ac][i].first[j] - 1));
        }
      }
      cout << (et[ac][i].second + 1) << ' ';
      return;
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> te(3);
    vector<vector<int> > ter(n, te);
    map<pair<int, int>, int> bo;
    map<pair<int, int>, int>::iterator it;
    vector<vector<int> > ad(n);
    vector<int> oc(n);
    vector<vector<pair<vector<int>, int> > > et(n);
    for (int i = 0; i < n - 2; i++) {
      for (int j = 0; j < 3; j++) cin >> ter[i][j];
      sort(ter[i].begin(), ter[i].end());
      for (int j = 0; j < 3; j++) {
        for (int k = j + 1; k < 3; k++)
          bo[pair<int, int>(ter[i][j], ter[i][k])]++;
        oc[ter[i][j] - 1]++;
        et[ter[i][j] - 1].push_back(pair<vector<int>, int>(ter[i], i));
      }
    }
    priority_queue<pair<int, int> > pq;
    for (int i = 0; i < n; i++)
      if (oc[i] == 1) {
        pq.push(pair<int, int>(-oc[i], i));
      }
    for (it = bo.begin(); it != bo.end(); it++)
      if (it->second == 1) {
        pair<int, int> ed = it->first;
        ad[ed.first - 1].push_back(ed.second - 1);
        ad[ed.second - 1].push_back(ed.first - 1);
      }
    vector<int> vi(n, 0);
    dfs(0, ad, vi);
    cout << endl;
    vector<int> vi2(n - 2, 0);
    while (!pq.empty()) {
      pair<int, int> b = pq.top();
      pq.pop();
      up(b.second, et, oc, vi2, pq);
    }
    cout << endl;
  }
  return 0;
}
