#include <bits/stdc++.h>
using namespace std;
char buf[1 << 15], *p1 = buf, *p2 = buf;
inline long long read() {
  char ch;
  bool flag = 0;
  long long res;
  while (!isdigit(
      ch = (p1 == p2 &&
                    (p2 = (p1 = buf) + fread(buf, 1, 1 << 15, stdin), p1 == p2)
                ? EOF
                : *p1++)))
    (ch == '-') && (flag = true);
  for (res = ch - '0'; isdigit(
           ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 15, stdin),
                             p1 == p2)
                     ? EOF
                     : *p1++));
       res = res * 10ll + ch - '0')
    ;
  (flag) && (res = -res);
  return res;
}
inline void write(long long x) {
  if (x < 0) x = ~x + 1ll, putchar('-');
  if (x > 9) write(x / 10ll);
  putchar(x % 10ll + '0');
}
vector<int> G[101000];
int deg[101000];
struct node {
  int x, y, z;
};
node a[101000];
int line[101000][3];
map<pair<int, int>, int> mp;
int cnt = 0;
int n;
pair<int, int> mak(int x, int y) { return make_pair(min(x, y), max(x, y)); }
void pf(int x, int fa) {
  printf("%d ", x);
  cnt++;
  if (cnt == n + 2) return;
  if (line[x][1] != fa)
    pf(line[x][1], x);
  else
    pf(line[x][2], x);
}
queue<int> q;
bool vis[101000];
int ans[101000];
void topo() {
  if (n == 1) {
    printf("1\n");
    return;
  }
  for (register int i = (1); i <= (n); i++)
    if (deg[i] == 1) q.push(i);
  int num = 0;
  while (!q.empty()) {
    int x = q.front();
    printf("%d ", x);
    q.pop();
    for (int i = 0; i < G[x].size(); i++) {
      int v = G[x][i];
      if (vis[v]) continue;
      deg[v]--;
      if (deg[v] == 1) q.push(v);
    }
  }
  puts("");
}
void solve() {
  n = read();
  n -= 2;
  mp.clear();
  cnt = 0;
  for (register int i = (1); i <= (n + 2); i++) {
    deg[i] = 0;
    G[i].clear();
    vis[i] = false;
    line[i][0] = line[i][1] = line[i][2] = 0;
  }
  for (register int i = (1); i <= (n); i++) {
    a[i].x = read();
    a[i].y = read();
    a[i].z = read();
    pair<int, int> lin = mak(a[i].x, a[i].y);
    if (mp.count(lin)) {
      int pos = mp[lin];
      G[pos].push_back(i);
      G[i].push_back(pos);
      deg[pos]++, deg[i]++;
      mp.erase(lin);
    } else
      mp[lin] = i;
    lin = mak(a[i].x, a[i].z);
    if (mp.count(lin)) {
      int pos = mp[lin];
      G[pos].push_back(i);
      G[i].push_back(pos);
      deg[pos]++, deg[i]++;
      mp.erase(lin);
    } else
      mp[lin] = i;
    lin = mak(a[i].z, a[i].y);
    if (mp.count(lin)) {
      int pos = mp[lin];
      G[pos].push_back(i);
      G[i].push_back(pos);
      deg[pos]++, deg[i]++;
      mp.erase(lin);
    } else
      mp[lin] = i;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    int x = (it->first).first, y = it->first.second;
    line[x][++line[x][0]] = y;
    line[y][++line[y][0]] = x;
  }
  pf(1, 0);
  puts("");
  topo();
}
int main() {
  int T = read();
  while (T--) solve();
}
