#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
pair<long long, long long> pair_up(long long a, long long b) {
  return {min(a, b), max(a, b)};
}
const long long N = 1e5 + 5;
long long vis[N], n;
vector<pair<long long, pair<long long, long long> > > graph;
vector<long long> edges[3 * N];
vector<long long> graph2[N];
vector<long long> graph3[N];
vector<pair<long long, long long> > edge;
unordered_map<pair<long long, long long>, long long, hash_pair> edge_no;
void dfs(long long p) {
  if (vis[p] != -1) return;
  vis[p] = 1;
  cout << p << " ";
  dfs(graph2[p][0]);
  dfs(graph2[p][1]);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long i, j, first, t, second, no, eno;
  cin >> t;
  while (t--) {
    long long a, b, c, tedge = 0;
    cin >> n;
    first = 0;
    for (i = 0; i < n - 2; i++) {
      cin >> a >> b >> c;
      vector<long long> arr = {a, b, c};
      graph.push_back({a, {b, c}});
      for (j = 0; j < 3; j++) {
        pair<long long, long long> p = pair_up(arr[j], arr[(j + 1) % 3]);
        if (edge_no.count(p)) {
          no = edge_no[p];
          edges[no].push_back(i);
        } else {
          edge_no[p] = first;
          edges[first].push_back(i);
          edge.push_back(p);
          first++;
        }
      }
    }
    eno = first;
    for (i = 0; i < first; i++) {
      if (edges[i].size() == 1) {
        graph2[edge[i].first].push_back(edge[i].second);
        graph2[edge[i].second].push_back(edge[i].first);
      } else {
        graph3[edges[i][0]].push_back(edges[i][1]);
        graph3[edges[i][1]].push_back(edges[i][0]);
      }
    }
    for (i = 0; i < n + 1; i++) {
      vis[i] = -1;
    }
    dfs(1);
    for (i = 0; i < n + 1; i++) {
      vis[i] = -1;
    }
    queue<long long> q;
    long long degre[n];
    for (i = 0; i < n - 2; i++) {
      degre[i] = graph3[i].size();
      if (graph3[i].size() == 1) {
        q.push(i);
        vis[i] = 1;
      }
    }
    cout << '\n';
    while (!q.empty()) {
      first = q.front();
      q.pop();
      cout << first + 1 << " ";
      for (i = 0; i < graph3[first].size(); i++) {
        second = graph3[first][i];
        if (vis[second] == -1) {
          if (degre[second] != 2)
            degre[second]--;
          else {
            vis[second] = 1;
            q.push(second);
          }
        }
      }
    }
    for (i = 0; i <= n; i++) {
      graph2[i].clear();
      graph3[i].clear();
      vis[i] = -1;
    }
    for (i = 0; i < eno; i++) edges[i].clear();
    graph.clear();
    edge.clear();
    edge_no.clear();
    if (n == 3) cout << 1;
    cout << '\n';
  }
  return 0;
}
