#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
int n, t, pv[maxN], nxt[maxN], vs[3];
struct Tri {
  int verts[3];
  Tri() {}
  Tri(int a, int b, int c) {
    verts[0] = a;
    verts[1] = b;
    verts[2] = c;
  }
  pair<int, int> getEdge(int x) {
    vector<int> res;
    for (int i = 0; i < 3; i++) {
      if (verts[i] != x) res.push_back(verts[i]);
    }
    return {res[0], res[1]};
  }
};
vector<Tri> tris;
map<pair<int, int>, vector<pair<int, int> > > mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> t;
  while (t--) {
    cin >> n;
    tris.clear();
    mp = map<pair<int, int>, vector<pair<int, int> > >();
    for (int i = 0; i < n - 2; i++) {
      cin >> vs[0] >> vs[1] >> vs[2];
      sort(vs, vs + 3);
      tris.emplace_back(vs[0], vs[1], vs[2]);
      mp[{vs[0], vs[1]}].emplace_back(i, vs[2]);
      mp[{vs[0], vs[2]}].emplace_back(i, vs[1]);
      mp[{vs[1], vs[2]}].emplace_back(i, vs[0]);
    }
    iota(pv, pv + n, 0);
    iota(nxt, nxt + n, 0);
    nxt[tris[0].verts[2]] = pv[tris[0].verts[1]] = tris[0].verts[0];
    nxt[tris[0].verts[0]] = pv[tris[0].verts[2]] = tris[0].verts[1];
    nxt[tris[0].verts[1]] = pv[tris[0].verts[0]] = tris[0].verts[2];
    queue<pair<int, int> > que;
    vector<int> ord;
    ord.push_back(0);
    for (int i = 0; i < 3; i++) que.push({0, tris[0].verts[i]});
    pair<int, int> tp, edge;
    Tri triangle;
    while (que.size()) {
      tp = que.front();
      que.pop();
      triangle = tris[tp.first];
      edge = triangle.getEdge(tp.second);
      for (auto p : mp[{edge.first, edge.second}]) {
        if (p.first == tp.first) continue;
        int tri_id = p.first, otherV = p.second;
        if (nxt[edge.first] == edge.second) {
          nxt[edge.first] = pv[edge.second] = otherV;
          pv[otherV] = edge.first;
          nxt[otherV] = edge.second;
        } else {
          nxt[edge.second] = pv[edge.first] = otherV;
          nxt[otherV] = edge.first;
          pv[otherV] = edge.second;
        }
        que.push({tri_id, edge.first});
        que.push({tri_id, edge.second});
        ord.push_back(tri_id);
      }
    }
    int current = 1;
    do {
      cout << current << " ";
      current = nxt[current];
    } while (current != 1);
    cout << '\n';
    reverse(ord.begin(), ord.end());
    for (int x : ord) cout << x + 1 << " ";
    cout << '\n';
  }
}
