#include <bits/stdc++.h>
using namespace std;
template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
void setmax(T& a, T b) {
  a = max(a, b);
};
template <typename T>
void setmin(T& a, T b) {
  a = min(a, b);
};
void solve() {
  int n;
  cin >> n;
  vector<vector<int>> pieces(n - 2);
  map<vector<int>, int> position;
  for (int i = 0; i < n - 2; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    --c;
    vector<int> piece = {a, b, c};
    sort(piece.begin(), piece.end());
    position[piece] = i;
    pieces[i] = piece;
  }
  vector<multiset<int>> g(n);
  for (auto& vec : pieces) {
    int a = vec[0], b = vec[1], c = vec[2];
    g[a].insert(b);
    g[a].insert(c);
    g[b].insert(a);
    g[b].insert(c);
    g[c].insert(a);
    g[c].insert(b);
  }
  minheap<pair<int, int>> degrees;
  for (int i = 0; i < n; i++) {
    degrees.push({g[i].size(), i});
  }
  vector<int> used(n, 0);
  vector<int> q;
  set<pair<int, int>> cross_edges;
  vector<vector<int>> cyc(n);
  for (int p = 0; p < n - 2; p++) {
    auto [_, x] = degrees.top();
    degrees.pop();
    if (used[x] == 1) continue;
    used[x] = 1;
    assert(g[x].size() == 2);
    int y = *g[x].begin();
    int z = *g[x].rbegin();
    if (p < n - 3)
      cross_edges.insert({min(y, z), max(y, z)});
    else {
      if (!cross_edges.count({min(y, z), max(y, z)})) {
        cyc[y].push_back(z);
        cyc[z].push_back(y);
      }
    }
    if (!cross_edges.count({min(x, y), max(x, y)})) {
      cyc[x].push_back(y);
      cyc[y].push_back(x);
    }
    if (!cross_edges.count({min(x, z), max(x, z)})) {
      cyc[x].push_back(z);
      cyc[z].push_back(x);
    }
    vector<int> piece = {x, y, z};
    sort(piece.begin(), piece.end());
    q.push_back(position[piece]);
    g[x].clear();
    g[y].erase(g[y].find(x));
    g[y].erase(g[y].find(z));
    g[z].erase(g[z].find(x));
    g[z].erase(g[z].find(y));
    degrees.push({g[y].size(), y});
    degrees.push({g[z].size(), z});
  }
  vector<int> p;
  used.assign(n, 0);
  function<void(int, int)> dfs = [&](int x, int par) -> void {
    p.push_back(x);
    used[x] = 1;
    for (int y : cyc[x]) {
      if (y != par && !used[y]) dfs(y, x);
    }
  };
  dfs(0, -1);
  for (int x : p) {
    cout << x + 1 << " ";
  }
  cout << '\n';
  for (int x : q) {
    cout << x + 1 << " ";
  }
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
