#include <bits/stdc++.h>
using namespace std;
int n, T;
void swapo(int &a, int &b, int &c) {
  if (a > b) swap(a, b);
  if (b > c)
    swap(b, c);
  else
    return;
  if (a > b) swap(a, b);
}
bool cmp(pair<int, int> u, pair<int, int> v) {
  if (u.first > v.first) return true;
  if (u.first == v.first) {
    if (u.second > v.second) return true;
  }
  return false;
}
struct cmp2 {
  bool operator()(pair<int, int> u, pair<int, int> v) {
    if (u.second > v.second) return true;
    return false;
  }
};
priority_queue<pair<int, int>, vector<pair<int, int> >, cmp2> vertex;
vector<int> id[100008];
int sum[100008];
vector<pair<int, int> > edge;
int link[100008][3];
deque<int> edg_;
bool bol[100008];
int triangle[100008][4];
void process_p() {
  int u;
  memset(bol, 0, sizeof(bol));
  edg_.push_back(1);
  bol[1] = 1;
  edg_.push_back(link[1][1]);
  bol[link[1][1]] = 1;
  u = link[1][1];
  while (bol[link[u][1]] == 0 || bol[link[u][2]] == 0) {
    if (bol[link[u][1]] == 0) {
      u = link[u][1];
      edg_.push_back(u);
      bol[u] = 1;
    } else if (bol[link[u][2]] == 0) {
      u = link[u][2];
      edg_.push_back(u);
      bol[u] = 1;
    }
  }
  while (!edg_.empty()) {
    cout << edg_.front() << " ";
    edg_.pop_front();
  }
  cout << endl;
}
void pus(int tri, int u) {
  int a, b;
  if (triangle[tri][1] == u)
    a = triangle[tri][2], b = triangle[tri][3];
  else if (triangle[tri][2] == u)
    a = triangle[tri][1], b = triangle[tri][3];
  else
    a = triangle[tri][1], b = triangle[tri][2];
  sum[a]--;
  vertex.push(pair<int, int>(a, sum[a]));
  sum[b]--;
  vertex.push(pair<int, int>(b, sum[b]));
  for (int i = 0; i < id[a].size(); i++)
    if (id[a][i] == tri) {
      id[a].erase(id[a].begin() + i);
      break;
    }
  for (int i = 0; i < id[b].size(); i++)
    if (id[b][i] == tri) {
      id[b].erase(id[b].begin() + i);
      break;
    }
}
int main() {
  cin >> T;
  int a, b, c;
  int u, v;
  while (T--) {
    cin >> n;
    memset(link, 0, sizeof(link));
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= n; i++) id[i].clear();
    for (int i = 1; i <= n - 2; i++) {
      cin >> a >> b >> c;
      id[a].push_back(i);
      id[b].push_back(i);
      id[c].push_back(i);
      sum[a]++;
      sum[b]++;
      sum[c]++;
      swapo(a, b, c);
      triangle[i][1] = a;
      triangle[i][2] = b;
      triangle[i][3] = c;
      edge.push_back(pair<int, int>(a, b));
      edge.push_back(pair<int, int>(a, c));
      edge.push_back(pair<int, int>(b, c));
    }
    sort(edge.begin(), edge.end(), cmp);
    while (!edge.empty()) {
      u = edge.back().first;
      v = edge.back().second;
      edge.pop_back();
      if (!edge.empty() && edge.back() == pair<int, int>(u, v)) {
        while (edge.back() == pair<int, int>(u, v)) edge.pop_back();
      } else {
        if (link[u][1] == 0)
          link[u][1] = v;
        else if (link[u][2] == 0)
          link[u][2] = v;
        if (link[v][1] == 0)
          link[v][1] = u;
        else if (link[v][2] == 0)
          link[v][2] = u;
      }
    }
    process_p();
    while (!vertex.empty()) vertex.pop();
    for (int i = 1; i <= n; i++) vertex.push(pair<int, int>(i, sum[i]));
    u = 0;
    while (u < n - 2) {
      u++;
      v = vertex.top().first;
      vertex.pop();
      cout << id[v][0] << " ";
      id[v].clear();
      pus(id[v][0], v);
    }
    cout << endl;
  }
}
