#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
vector<int> adj[maxn];
vector<int> vis;
void dfs(int v) {
  cout << v << " ";
  vis[v] = 1;
  for (int to : adj[v])
    if (!vis[to]) dfs(to);
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) adj[i].clear();
  vector<int> A(n + 1), B(n + 1), C(n + 1);
  set<int> belong[n + 1];
  map<int, int> mp[n + 1];
  for (int i = 1; i <= n - 2; i++) {
    cin >> A[i] >> B[i] >> C[i];
    belong[A[i]].insert(i);
    belong[B[i]].insert(i);
    belong[C[i]].insert(i);
    mp[A[i]][B[i]]++;
    mp[A[i]][C[i]]++;
    mp[B[i]][C[i]]++;
    mp[B[i]][A[i]]++;
    mp[C[i]][A[i]]++;
    mp[C[i]][B[i]]++;
  }
  set<int> se;
  for (int i = 1; i <= n; i++)
    if ((int)belong[i].size() == 1) se.insert(*belong[i].begin());
  vector<int> piece_order;
  for (int i = 1; i <= n - 2; i++) {
    int j = *se.begin();
    se.erase(se.begin());
    piece_order.push_back(j);
    belong[A[j]].erase(j);
    belong[B[j]].erase(j);
    belong[C[j]].erase(j);
    if ((int)belong[A[j]].size() == 1) se.insert(*belong[A[j]].begin());
    if ((int)belong[B[j]].size() == 1) se.insert(*belong[B[j]].begin());
    if ((int)belong[C[j]].size() == 1) se.insert(*belong[C[j]].begin());
  }
  for (int i = 1; i <= n; i++)
    for (pair<int, int> a : mp[i])
      if (a.second == 1) adj[i].push_back(a.first);
  vis = vector<int>(n + 1, 0);
  dfs(1);
  cout << "\n";
  for (int j : piece_order) cout << j << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
