#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e+5;
int v[maxn];
vector<int> g[maxn];
int visit[maxn];
void dfs(int x) {
  visit[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    int cur = g[x][i];
    if (visit[cur] == 0) dfs(g[x][i]);
  }
  cout << x << " ";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i <= maxn; i++) {
      v[i] = 0;
      visit[i] = 0;
      g[i].clear();
    }
    map<pair<int, int>, vector<int> > mp;
    for (int i = 0; i < n - 2; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      if (a > b) swap(a, b);
      if (b > c) swap(b, c);
      if (a > b) swap(a, b);
      v[a] ^= b, v[a] ^= c;
      v[b] ^= a, v[b] ^= c;
      v[c] ^= a, v[c] ^= b;
      mp[{a, b}].push_back(i + 1);
      mp[{a, c}].push_back(i + 1);
      mp[{b, c}].push_back(i + 1);
    }
    int a, b;
    for (auto h : mp) {
      if (h.second.size() == 1) {
        a = h.first.first;
        b = h.first.second;
      }
    }
    cout << a << " " << b;
    for (int i = 0; i < n - 2; i++) {
      int t = a ^ v[b];
      cout << " " << t;
      a = b, b = t;
    }
    cout << endl;
    for (auto h : mp) {
      if (h.second.size() == 2) {
        int u = h.second[0], v = h.second[1];
        g[u].push_back(v), g[v].push_back(u);
      }
    }
    dfs(1);
    cout << endl;
  }
  return 0;
}
