#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int maxn = 1e5 + 43;
const int maxm = 2e3 + 43;
const int maxlog = 30;
const long long mod = (long long)1e9 + 7;
const int sq = 340;
const int inf = 1e9;
const long double PI = 3.141592653589793238463;
vector<int> adj[maxn];
vector<int> adj2[maxn];
map<pair<int, int>, vector<int> > other;
vector<pair<int, int> > vec[maxn];
int cnt2[maxn];
int tof[3];
int cnt[maxn];
int n;
vector<int> ans;
bool mark[maxn];
map<pair<pair<int, int>, int>, int> id;
int get_id(int v1, int v2, int v3) {
  tof[0] = v1;
  tof[1] = v2;
  tof[2] = v3;
  sort(tof, tof + 3);
  int vv1 = tof[0];
  int vv2 = tof[1];
  int vv3 = tof[2];
  return id[make_pair(make_pair(vv1, vv2), vv3)];
}
void dfs(int v1, int v2) {
  for (int j = 0; j < other[make_pair(min(v1, v2), max(v1, v2))].size(); j++) {
    int v3 = other[make_pair(min(v1, v2), max(v1, v2))][j];
    if (v3 == 0 || mark[v3]) continue;
    mark[v3] = true;
    dfs(v1, v3);
    dfs(v3, v2);
    ans.push_back(get_id(v1, v2, v3));
    adj[v1].push_back(v3);
    adj[v3].push_back(v2);
    adj2[v3].push_back(v1);
    adj2[v2].push_back(v3);
  }
}
void solve1() {
  int s = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt[i] == 1) {
      s = i;
      break;
    }
  }
  mark[s] = true;
  int v1 = vec[s][0].first;
  int v2 = vec[s][0].second;
  ans.push_back(get_id(s, v1, v2));
  mark[v1] = true;
  mark[v2] = true;
  adj[v1].push_back(v2);
  adj2[v2].push_back(v1);
  dfs(v1, v2);
  set<pair<int, int> > st;
  for (int i = 1; i <= n; i++) {
    if (i == s) continue;
    cnt2[i] = (int)adj[i].size();
    st.insert(make_pair(cnt2[i], i));
  }
  int cur = 2;
  cout << s << " ";
  for (int i = 0; i < n - 1; i++) {
    int v = (*st.begin()).second;
    cout << v << " ";
    cur++;
    st.erase(st.begin());
    for (int j = 0; j < adj2[v].size(); j++) {
      int u = adj2[v][j];
      st.erase(make_pair(cnt2[u], u));
      cnt2[u]--;
      st.insert(make_pair(cnt2[u], u));
    }
  }
  cout << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    other.clear();
    ans.clear();
    for (int i = 1; i <= n; i++) {
      adj[i].clear();
      adj2[i].clear();
      cnt[i] = 0;
      vec[i].clear();
      mark[i] = false;
    }
    for (int i = 0; i < n - 2; i++) {
      cin >> tof[0] >> tof[1] >> tof[2];
      sort(tof, tof + 3);
      int v1 = tof[0], v2 = tof[1], v3 = tof[2];
      other[make_pair(v1, v2)].push_back(v3);
      other[make_pair(v2, v3)].push_back(v1);
      other[make_pair(v1, v3)].push_back(v2);
      cnt[v1]++;
      cnt[v2]++;
      cnt[v3]++;
      vec[v1].push_back(make_pair(v2, v3));
      vec[v2].push_back(make_pair(v1, v3));
      vec[v3].push_back(make_pair(v1, v2));
      id[make_pair(make_pair(v1, v2), v3)] = i + 1;
    }
    solve1();
  }
  return 0;
}
