#include <bits/stdc++.h>
using namespace std;
int t, n, a, b, c;
vector<int> adj_v[100005], adj_s[100005];
map<pair<int, int>, int> edges;
void add_edge(int a, int b, int i) {
  pair<int, int> p(a, b);
  if (edges.find(p) != edges.end()) {
    int j = edges.find(p)->second;
    adj_s[i].push_back(j);
    adj_s[j].push_back(i);
    edges.erase(edges.find(p));
  } else {
    edges.insert({p, i});
  }
}
void print_slices(int i, int p) {
  for (int next : adj_s[i]) {
    if (p != next) {
      print_slices(next, i);
    }
  }
  cout << i << " ";
}
void print_vertices(int i, int p) {
  if (i == 1 && p != 0) {
    cout << endl;
    return;
  }
  cout << i << " ";
  if (p == 0)
    print_vertices(adj_v[i][0], i);
  else if (adj_v[i][0] != p)
    print_vertices(adj_v[i][0], i);
  else
    print_vertices(adj_v[i][1], i);
}
int main() {
  for (int i = 1; i < 100005; i++) {
    adj_v[i] = vector<int>();
    adj_s[i] = vector<int>();
  }
  cin >> t;
  while (t > 0) {
    edges.clear();
    cin >> n;
    for (int i = 1; i <= n; i++) {
      adj_v[i].clear();
      adj_s[i].clear();
    }
    for (int i = 1; i < n - 1; i++) {
      cin >> a >> b >> c;
      if (a < b) swap(a, b);
      if (a < c) swap(a, c);
      if (b < c) swap(b, c);
      add_edge(a, b, i);
      add_edge(b, c, i);
      add_edge(a, c, i);
    }
    for (auto p = edges.begin(); p != edges.end(); p++) {
      a = p->first.first;
      b = p->first.second;
      adj_v[a].push_back(b);
      adj_v[b].push_back(a);
    }
    print_vertices(1, 0);
    print_slices(1, 0);
    cout << endl;
    t--;
  }
  return 0;
}
