#include <bits/stdc++.h>
using namespace std;
struct piece {
  int a, b, c;
};
int t;
int fat[100002], sz[100002];
int get(int a) {
  if (fat[a] == a) return a;
  return fat[a] = get(fat[a]);
}
void unite(int a, int b) {
  a = get(a), b = get(b);
  if (sz[a] < sz[b]) swap(a, b);
  sz[a] += sz[b];
  fat[b] = a;
}
vector<int> vec[100005];
int vis[100005];
void link(int a, int b) {
  if (get(a) != get(b)) {
    vec[a].push_back(b);
    vec[b].push_back(a);
    unite(a, b);
  }
}
void dfs(int nod) {
  if (vis[nod]) return;
  cout << nod << " ";
  vis[nod] = 1;
  for (auto i : vec[nod]) dfs(i);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<piece> v(n - 1);
    vector<int> solq;
    set<int> s[n + 1];
    queue<int> q;
    for (int i = 1; i <= n - 2; ++i) {
      cin >> v[i].a >> v[i].b >> v[i].c;
      s[v[i].a].insert(i);
      s[v[i].b].insert(i);
      s[v[i].c].insert(i);
    }
    for (int i = 1; i <= n; ++i) {
      if (s[i].size() == 1) q.push(i);
      fat[i] = i;
      vec[i].clear();
      vis[i] = 0;
    }
    int aux = n - 2;
    while (aux--) {
      int ver = q.front();
      q.pop();
      int tri = (*s[ver].begin());
      int a = v[tri].a, b = v[tri].b, c = v[tri].c;
      if (a == ver) {
        link(a, b);
        link(a, c);
      } else if (b == ver) {
        link(a, b);
        link(b, c);
      } else {
        link(a, c);
        link(b, c);
      }
      solq.push_back(tri);
      s[a].erase(tri);
      if (s[a].size() == 1) q.push(a);
      s[b].erase(tri);
      if (s[b].size() == 1) q.push(b);
      s[c].erase(tri);
      if (s[c].size() == 1) q.push(c);
    }
    for (int i = 1; i <= n; ++i) {
      if (vec[i].size() == 1) {
        dfs(i);
        break;
      }
    }
    cout << "\n";
    for (auto i : solq) cout << i << " ";
    cout << "\n";
  }
  return 0;
}
