#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long double EPS = 1e-9;
long long binpow(long long b, long long p, long long mod) {
  long long ans = 1;
  b %= mod;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
long long n;
vector<vector<long long> > vv;
map<pair<long long, long long>, vector<long long> > canbe;
map<pair<long long, long long>, long long> edges;
vector<long long> ans2;
vector<long long> viis;
vector<vector<long long> > g;
void dfs(long long nn) {
  viis[nn] = 1;
  ans2.emplace_back(nn);
  for (auto v : g[nn]) {
    if (!viis[v]) {
      dfs(v);
    }
  }
}
void solve() {
  cin >> n;
  edges.clear();
  canbe.clear();
  vv.clear();
  g.clear();
  ans2.clear();
  g.resize(n + 1);
  viis.assign(n + 1, 0);
  for (long long i = 0; i < (n - 2); ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    vector<long long> arr = {a, b, c};
    sort((arr).begin(), (arr).end());
    arr.emplace_back(i);
    vv.push_back(arr);
    canbe[make_pair(arr[0], arr[1])].emplace_back(i);
    canbe[make_pair(arr[0], arr[2])].emplace_back(i);
    canbe[make_pair(arr[1], arr[2])].emplace_back(i);
    edges[make_pair(arr[0], arr[1])]++;
    edges[make_pair(arr[0], arr[2])]++;
    edges[make_pair(arr[1], arr[2])]++;
  }
  for (auto v : edges) {
    if (v.second == 1) {
      g[v.first.first].emplace_back(v.first.second);
      g[v.first.second].emplace_back(v.first.first);
    }
  }
  vector<long long> vis(n - 2, 0);
  vector<long long> deg(n - 2, 0);
  for (long long i = 0; i < (n - 2); ++i) {
    if ((long long)(canbe[make_pair(vv[i][0], vv[i][1])]).size() > 1) deg[i]++;
    if ((long long)(canbe[make_pair(vv[i][1], vv[i][2])]).size() > 1) deg[i]++;
    if ((long long)(canbe[make_pair(vv[i][0], vv[i][2])]).size() > 1) deg[i]++;
  }
  queue<long long> q;
  for (long long i = 0; i < (n - 2); ++i) {
    if (deg[i] <= 1) {
      q.push(i);
      vis[i] = 1;
    }
  }
  vector<long long> ans;
  while (!q.empty()) {
    long long i = q.front();
    ans.emplace_back(i);
    q.pop();
    for (auto v : canbe[make_pair(vv[i][0], vv[i][1])]) {
      if (!vis[v]) {
        deg[v]--;
        if (deg[v] <= 1) {
          q.push(v);
          vis[v] = 1;
        }
      }
    }
    for (auto v : canbe[make_pair(vv[i][1], vv[i][2])]) {
      if (!vis[v]) {
        deg[v]--;
        if (deg[v] <= 1) {
          q.push(v);
          vis[v] = 1;
        }
      }
    }
    for (auto v : canbe[make_pair(vv[i][0], vv[i][2])]) {
      if (!vis[v]) {
        deg[v]--;
        if (deg[v] <= 1) {
          q.push(v);
          vis[v] = 1;
        }
      }
    }
  }
  dfs(1);
  for (auto v : ans2) {
    cout << v << " ";
  }
  cout << '\n';
  for (auto v : ans) {
    cout << v + 1 << " ";
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long _t = 1;
  cin >> _t;
  for (long long i = 1; i <= _t; i++) {
    solve();
  }
}
