#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int MN = 1e5 + 5;
int T, N, cnt[MN], lft[MN], rht[MN], deg[MN];
bool vis[MN], done[MN];
map<vector<int>, int> rev;
vector<vector<int>> v;
map<pair<int, int>, vector<int>> m;
vector<int> g[MN];
inline void reset() {
  rev.clear();
  v.clear();
  m.clear();
}
inline int not_common(vector<int> &a, vector<int> &b) {
  for (int i = 0; i < 3; i++) {
    if (find(begin(a), end(a), b[i]) != a.end()) continue;
    return b[i];
  }
  assert(false);
}
inline void add(int a, int b, int n) {
  if (rht[a] != b) swap(a, b);
  lft[n] = a, rht[n] = b;
  rht[a] = n, lft[b] = n;
}
void dfs(int u, int p) {
  for (int ch : g[u]) {
    if (ch == p) continue;
    int n = not_common(v[u], v[ch]);
    vector<int> other;
    for (int ck : v[ch])
      if (ck != n) other.push_back(ck);
    add(other[0], other[1], n);
    dfs(ch, u);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> T;
  while (T--) {
    cin >> N;
    reset();
    for (int i = 0; i <= N; i++) {
      g[i].clear(), cnt[i] = 0;
      lft[i] = rht[i] = deg[i] = 0;
      vis[i] = done[i] = false;
    }
    for (int i = 3; i <= N; i++) {
      vector<int> t;
      for (int k = 0; k < 3; k++) {
        int a;
        cin >> a;
        t.push_back(a);
        cnt[a]++;
      }
      sort(begin(t), end(t));
      v.push_back(t);
      m[{t[0], t[1]}].push_back(i - 3);
      m[{t[1], t[2]}].push_back(i - 3);
      m[{t[0], t[2]}].push_back(i - 3);
    }
    for (int i = 0; i < v.size(); i++) rev[v[i]] = i;
    int rt = -1, al = -1;
    vector<int> tmp;
    for (int i = 0; i < v.size(); i++) {
      for (int a = 0; a < 3; a++) {
        for (int b = a + 1; b < 3; b++) {
          vector<int> &v2 = m[{v[i][a], v[i][b]}];
          for (int ck : v2) {
            if (ck == i) continue;
            g[i].push_back(ck);
            deg[i]++;
          }
        }
        if (cnt[v[i][a]] == 1) {
          rt = i, al = v[i][a];
          if (a == 0)
            tmp = {v[i][1], v[i][2]};
          else if (a == 1)
            tmp = {v[i][0], v[i][2]};
          else
            tmp = {v[i][0], v[i][1]};
        }
      }
    }
    rht[tmp[0]] = al, lft[tmp[0]] = tmp[1];
    lft[tmp[1]] = al, rht[tmp[1]] = tmp[0];
    lft[al] = tmp[0], rht[al] = tmp[1];
    dfs(rt, -1);
    int curr = al;
    while (!vis[curr]) {
      vis[curr] = true;
      cout << curr << " ";
      curr = rht[curr];
    }
    cout << "\n";
    vector<int> t;
    for (int i = 0; i < v.size(); i++)
      if (deg[i] <= 1) done[i] = true, t.push_back(i);
    while (t.size()) {
      int n = t.back();
      t.pop_back();
      cout << n + 1 << " ";
      for (int ck : g[n]) {
        if (done[ck]) continue;
        deg[ck]--;
        if (deg[ck] <= 1) {
          done[ck] = true;
          t.push_back(ck);
        }
      }
    }
    cout << "\n";
  }
}
