#include <bits/stdc++.h>
using namespace std;
int n, x, y, z;
vector<multiset<int> > v;
set<pair<pair<int, int>, pair<int, int> > > q;
int tmp3[3];
vector<int> ans1, ans2;
bool chk[100005];
set<pair<int, int> > num;
void dfs(int beg) {
  chk[beg] = 1;
  ans1.push_back(beg);
  for (int x : v[beg]) {
    if (v[beg].count(x) == 1 && chk[x] == 0) {
      dfs(x);
      return;
    }
  }
}
void solve() {
  cin >> n;
  num.clear();
  v.clear();
  q.clear();
  ans1.clear();
  ans2.clear();
  v.resize(n + 1);
  fill(chk, chk + 100005, false);
  for (int(i) = (0); (i) < (n - 2); (i)++) {
    cin >> x >> y >> z;
    v[x].insert(y);
    v[x].insert(z);
    v[y].insert(x);
    v[y].insert(z);
    v[z].insert(x);
    v[z].insert(y);
    tmp3[0] = x;
    tmp3[1] = y;
    tmp3[2] = z;
    sort(tmp3, tmp3 + 3);
    q.insert(make_pair(make_pair(tmp3[0], tmp3[1]), make_pair(tmp3[2], i + 1)));
  }
  int beg, l, r;
  for (int(i) = (1); (i) < (n + 1); (i)++)
    num.insert(make_pair(v[i].size(), i));
  beg = (*num.begin()).second;
  dfs(beg);
  while (v[beg].size() == 2) {
    num.erase(num.find(make_pair(2, beg)));
    l = *(v[beg].begin());
    r = *(++v[beg].begin());
    tmp3[0] = beg;
    tmp3[1] = l;
    tmp3[2] = r;
    sort(tmp3, tmp3 + 3);
    ans2.push_back((*q.lower_bound(make_pair(make_pair(tmp3[0], tmp3[1]),
                                             make_pair(tmp3[2], 0))))
                       .second.second);
    v[beg].clear();
    num.erase(num.find(make_pair(v[l].size(), l)));
    num.erase(num.find(make_pair(v[r].size(), r)));
    num.insert(make_pair(v[l].size() - 2, l));
    num.insert(make_pair(v[r].size() - 2, r));
    v[l].erase(v[l].find(beg));
    v[r].erase(v[r].find(beg));
    v[l].erase(v[l].find(r));
    v[r].erase(v[r].find(l));
    beg = (*num.begin()).second;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int(i) = (0); (i) < (t); (i)++) {
    solve();
    for (int x : ans1) cout << x << " ";
    cout << "\n";
    for (int x : ans2) cout << x << " ";
    cout << "\n";
  }
  return 0;
}
