#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005][3];
map<pair<int, int>, vector<int>> mp;
map<pair<int, int>, bool> used;
vector<int> v[100005], g[100005];
int deg[100005];
int f[100005];
vector<int> path;
int same(int x, int y) {
  if (a[x][0] == a[y][0] && a[x][1] == a[y][1]) return 2;
  if (a[x][0] == a[y][0] && a[x][1] == a[y][2]) return 2;
  if (a[x][0] == a[y][1] && a[x][1] == a[y][2]) return 2;
  if (a[x][0] == a[y][0] && a[x][2] == a[y][1]) return 1;
  if (a[x][0] == a[y][0] && a[x][2] == a[y][2]) return 1;
  if (a[x][0] == a[y][1] && a[x][2] == a[y][2]) return 1;
  if (a[x][1] == a[y][0] && a[x][2] == a[y][1]) return 0;
  if (a[x][1] == a[y][0] && a[x][2] == a[y][2]) return 0;
  if (a[x][1] == a[y][1] && a[x][2] == a[y][2]) return 0;
}
void dfs(int now, int fa) {
  f[now] = fa;
  if (now != fa) {
    int s = same(now, fa);
    int x, y;
    for (int i = 0; i < 3; i++)
      if (i != s) {
        x = a[now][i];
        break;
      }
    for (int i = 2; i >= 0; i--)
      if (i != s) {
        y = a[now][i];
        break;
      }
    used[pair<int, int>(x, y)] = used[pair<int, int>(y, x)] = 1;
  }
  for (int x : v[now]) {
    if (x == fa) continue;
    dfs(x, now);
  }
  path.push_back(now);
}
vector<int> ans;
bool book[100005];
void DFS(int now) {
  ans.push_back(now);
  book[now] = 1;
  for (int x : g[now]) {
    if (book[x]) continue;
    DFS(x);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    mp.clear();
    path.clear();
    used.clear();
    ans.clear();
    for (int i = 1; i <= n; i++) {
      book[i] = 0;
      v[i].clear();
      deg[i] = 0;
      g[i].clear();
    }
    for (int i = 1; i <= n - 2; i++) {
      for (int j = 0; j < 3; j++) scanf("%d", &a[i][j]);
      sort(a[i], a[i] + 3);
      mp[make_pair(a[i][0], a[i][1])].push_back(i);
      mp[make_pair(a[i][0], a[i][2])].push_back(i);
      mp[make_pair(a[i][1], a[i][2])].push_back(i);
    }
    if (n == 3) {
      printf("1 2 3\n");
      printf("1\n");
      continue;
    }
    for (auto iter = mp.begin(); iter != mp.end(); iter++) {
      for (int i = 0; i < iter->second.size(); i++) {
        int x = iter->second[i];
        for (int j = i + 1; j < iter->second.size(); j++) {
          int y = iter->second[j];
          v[x].push_back(y);
          v[y].push_back(x);
          deg[x]++;
          deg[y]++;
        }
      }
    }
    dfs(1, 1);
    for (int i = 1; i <= n - 2; i++) {
      if (!used.count(make_pair(a[i][0], a[i][1]))) {
        g[a[i][0]].push_back(a[i][1]);
        g[a[i][1]].push_back(a[i][0]);
      }
      if (!used.count(make_pair(a[i][0], a[i][2]))) {
        g[a[i][0]].push_back(a[i][2]);
        g[a[i][2]].push_back(a[i][0]);
      }
      if (!used.count(make_pair(a[i][1], a[i][2]))) {
        g[a[i][1]].push_back(a[i][2]);
        g[a[i][2]].push_back(a[i][1]);
      }
    }
    DFS(1);
    for (int x : ans) printf("%d ", x);
    printf("\n");
    for (int x : path) printf("%d ", x);
    printf("\n");
  }
  return 0;
}
