#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, vector<int>> f;
vector<int> G[100005];
int vis[100005];
int s[100005];
void dfs(int u) {
  vis[u] = true;
  for (auto v : G[u]) {
    if (vis[v]) continue;
    dfs(v);
  }
  printf("%d ", u);
}
void Sort(int &a, int &b, int &c) {
  int s[4];
  s[1] = a;
  s[2] = b;
  s[3] = c;
  sort(s + 1, s + 1 + 3);
  a = s[1];
  b = s[2];
  c = s[3];
}
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    f.clear();
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) G[i].clear();
    for (int i = 1; i <= n; ++i) vis[i] = 0;
    for (int i = 1; i <= n; ++i) s[i] = 0;
    for (int i = 1; i <= n - 2; ++i) {
      int a;
      int b;
      int c;
      scanf("%d %d %d", &a, &b, &c);
      Sort(a, b, c);
      f[make_pair(a, b)].push_back(i);
      f[make_pair(a, c)].push_back(i);
      f[make_pair(b, c)].push_back(i);
      s[a] ^= (b ^ c);
      s[b] ^= (a ^ c);
      s[c] ^= (a ^ b);
    }
    int A;
    int B;
    for (auto t : f) {
      if (t.second.size() == 1) {
        A = t.first.first;
        B = t.first.second;
        break;
      }
    }
    printf("%d %d", A, B);
    for (int i = 1; i <= n - 2; ++i) {
      int nex = s[B] ^ A;
      printf(" %d", nex);
      A = B;
      B = nex;
    }
    printf("\n");
    for (auto t : f) {
      if (t.second.size() == 2) {
        int aa = t.first.first;
        int bb = t.first.second;
        int u = t.second[0];
        int v = t.second[1];
        G[u].push_back(v);
        G[v].push_back(u);
      }
    }
    dfs(1);
    printf("\n");
  }
  return 0;
}
