#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
int n;
set<int> g[maxn];
int a[maxn][3];
int l[maxn], r[maxn], vis[maxn], v1[maxn];
queue<int> q;
vector<int> ans, res;
vector<int> m[maxn];
void dfs(int x) {
  for (int i = 0; i < m[x].size(); i++) {
    if (!vis[m[x][i]]) {
      vis[m[x][i]] = 1;
      res.push_back(m[x][i]);
      dfs(m[x][i]);
      break;
    }
  }
}
int pre[maxn];
int find(int x) {
  if (pre[x] == x) return x;
  return pre[x] = find(pre[x]);
}
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx != fy) {
    pre[fx] = fy;
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      g[i].clear();
      l[i] = r[i] = vis[i] = v1[i] = 0;
      m[i].clear();
      pre[i] = i;
    }
    while (!q.empty()) q.pop();
    ans.clear();
    res.clear();
    for (int i = 1; i <= n - 2; i++) {
      for (int j = 0; j < 3; j++) {
        scanf("%d", &a[i][j]);
        g[a[i][j]].insert(i);
      }
    }
    for (int i = 1; i <= n; i++) {
      int x = *g[i].begin();
      if (g[i].size() == 1 && !v1[x]) {
        v1[x] = 1;
        q.push(x);
      }
    }
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      int tmp;
      ans.push_back(now);
      for (int i = 0; i < 3; i++) {
        if (g[a[now][i]].size() == 1) {
          tmp = i;
          break;
        }
      }
      for (int i = 0; i < 3; i++) {
        if (i != tmp) {
          int zz = a[now][tmp];
          int dd = a[now][i];
          if (find(zz) != find(dd)) {
            m[zz].push_back(dd);
            m[dd].push_back(zz);
          }
          merge(zz, dd);
        }
      }
      for (int i = 0; i < 3; i++) {
        g[a[now][i]].erase(now);
        int x = *g[a[now][i]].begin();
        if (g[a[now][i]].size() == 1 && !v1[x]) {
          v1[x] = 1;
          q.push(x);
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (m[i].size() == 1) {
        res.push_back(i);
        vis[i] = 1;
        dfs(i);
        break;
      }
    }
    for (int i = 0; i < res.size(); i++) {
      printf("%d ", res[i]);
    }
    printf("\n");
    for (int i = 0; i < ans.size(); i++) {
      printf("%d ", ans[i]);
    }
    printf("\n");
  }
}
