#include <bits/stdc++.h>
using namespace std;
multiset<int> v[100005];
map<pair<int, int>, int> no;
map<vector<int>, int> id;
vector<int> cut, v2[100005];
struct compare {
  bool operator()(const int& lhs, const int& rhs) const {
    int a, b;
    if ((a = ((int)v[lhs].size())) != (b = ((int)v[rhs].size()))) return a < b;
    return lhs < rhs;
  }
};
multiset<int, compare> nodes;
void update(vector<int> tri) {
  for (int i : tri) nodes.erase(nodes.find(i));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (i == j) continue;
      v[tri[i]].erase(v[tri[i]].find(tri[j]));
    }
  }
  for (int i : tri) {
    if (((int)v[i].size())) nodes.insert(i);
  }
}
void add_edge(int x, int y) {
  v[x].insert(y);
  v[y].insert(x);
}
void add_bound(int x, int y) {
  v2[x].push_back(y);
  v2[y].push_back(x);
}
void clear(int n) {
  cut.clear();
  id.clear();
  no.clear();
  for (int i = 1; i <= n; i++) v2[i].clear();
}
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n - 2; i++) {
    vector<int> tri(3);
    for (int j = 0; j < 3; j++) scanf("%d", &tri[j]);
    sort(tri.begin(), tri.end());
    for (int j = 0; j < 3; j++) {
      for (int k = j + 1; k < 3; k++) {
        add_edge(tri[j], tri[k]);
      }
    }
    id[tri] = i;
  }
  for (int i = 1; i <= n; i++) nodes.insert(i);
  while (((int)nodes.size())) {
    int node = *nodes.begin();
    assert(((int)v[node].size()) == 2);
    vector<int> tri;
    tri.push_back(node);
    for (int x : v[node]) tri.push_back(x);
    sort(tri.begin(), tri.end());
    cut.push_back(id[tri]);
    for (int i = 0; i < 3; i++) {
      int n1 = tri[i];
      for (int j = i + 1; j < 3; j++) {
        int n2 = tri[j];
        if (((int)v[n1].size()) == 2 || ((int)v[n2].size()) == 2) {
          if (!no[{n1, n2}]) add_bound(n1, n2);
        } else
          no[{n1, n2}] = 1;
      }
    }
    update(tri);
  }
  int node = 1, dad = 0;
  while (node != 1 || dad == 0) {
    printf("%d ", node);
    for (int i : v2[node])
      if (i != dad) {
        dad = node, node = i;
        break;
      }
  }
  printf("\n");
  for (auto x : cut) printf("%d ", x);
  printf("\n");
  clear(n);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
