#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 666;
map<int, int> ban[maxn];
int occ[maxn];
struct node {
  vector<int> v;
};
node ori[maxn];
set<int> saveid[maxn];
vector<int> G[maxn];
map<int, int> vis;
void dfs(int s, int f, int rt) {
  printf("%d ", s);
  for (int d : G[s]) {
    if (d == f || d == rt) continue;
    dfs(d, s, rt);
    return;
  }
}
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) {
    G[i].clear();
    saveid[i].clear();
    ori[i].v.clear();
    occ[i] = 0;
    ban[i].clear();
  }
  vis.clear();
  for (int i = 1; i <= n - 2; i++) {
    int a;
    for (int j = 1; j <= 3; j++) {
      scanf("%d", &a);
      ori[i].v.push_back(a);
      saveid[a].insert(i);
      occ[a]++;
    }
  }
  vector<int> top;
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (occ[i] == 1) q.push(i);
  }
  while (!q.empty() && top.size() < n - 3) {
    int nowid = q.front();
    q.pop();
    int iid = *saveid[nowid].begin();
    top.push_back(iid);
    for (int i = 0; i < 3; i++) {
      int pos = ori[iid].v[i];
      saveid[pos].erase(iid);
      occ[pos]--;
      if (occ[pos] == 1) {
        q.push(pos);
      }
      if (pos == nowid) {
        ban[ori[iid].v[(i + 1) % 3]][ori[iid].v[(i + 2) % 3]] = 1;
        ban[ori[iid].v[(i + 2) % 3]][ori[iid].v[(i + 1) % 3]] = 1;
      }
      if (pos == nowid || ban[nowid][pos]) continue;
      G[nowid].push_back(pos);
      G[pos].push_back(nowid);
    }
  }
  vis.clear();
  for (int id : top) {
    vis[id] = 1;
  }
  for (int i = 1; i <= n - 2; i++) {
    if (vis[i]) continue;
    top.push_back(i);
    for (int j = 0; j < 3; j++) {
      int pos = ori[i].v[j];
      int nexpos = ori[i].v[(j + 1) % 3];
      if (ban[pos][nexpos] == 0) {
        G[pos].push_back(nexpos);
        G[nexpos].push_back(pos);
      }
    }
  }
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    if (G[i].size() == 1) {
      dfs(i, i, i);
      flag = 1;
      break;
    }
  }
  if (!flag) {
    dfs(1, 1, 1);
  }
  puts("");
  for (int i : top) {
    printf("%d ", i);
  }
  puts("");
}
signed main() {
  int T;
  cin >> T;
  while (T--) solve();
}
