#include <bits/stdc++.h>
using namespace std;
const long long llinf = 9000000000000000000;
const int inf = 2000000000;
const long long hashnum = 100010;
int q;
int n;
unordered_map<long long, int> mp[2], mpp;
void in_hash(int a, int b, int c, int num) {
  mp[mp[0].count((long long)a * hashnum + (long long)b)]
    [(long long)a * hashnum + (long long)b] = c;
  mpp[a * hashnum * hashnum + b * hashnum + c] = num;
  swap(a, b);
  mp[mp[0].count((long long)a * hashnum + (long long)b)]
    [(long long)a * hashnum + (long long)b] = c;
  mpp[a * hashnum * hashnum + b * hashnum + c] = num;
  swap(a, c);
  mp[mp[0].count((long long)a * hashnum + (long long)b)]
    [(long long)a * hashnum + (long long)b] = c;
  mpp[a * hashnum * hashnum + b * hashnum + c] = num;
  swap(a, b);
  mp[mp[0].count((long long)a * hashnum + (long long)b)]
    [(long long)a * hashnum + (long long)b] = c;
  mpp[a * hashnum * hashnum + b * hashnum + c] = num;
  swap(a, c);
  mp[mp[0].count((long long)a * hashnum + (long long)b)]
    [(long long)a * hashnum + (long long)b] = c;
  mpp[a * hashnum * hashnum + b * hashnum + c] = num;
  swap(a, b);
  mp[mp[0].count((long long)a * hashnum + (long long)b)]
    [(long long)a * hashnum + (long long)b] = c;
  mpp[a * hashnum * hashnum + b * hashnum + c] = num;
}
void hash_clear() {
  mp[1].clear();
  mp[0].clear();
  mpp.clear();
}
int num[100010];
pair<int, int> p[100010];
int hull[100010], reh, rec, re;
pair<int, int> cut[100010];
bool ch[100010];
int rcut[100010];
void make_hull(int lv) {
  int next;
  if (!mp[1].count((long long)cut[lv].first * hashnum +
                   (long long)cut[lv].second)) {
    rec--;
    return;
  }
  ch[cut[lv].first] = true;
  ch[cut[lv].second] = true;
  if (ch[mp[0][(long long)cut[lv].first * hashnum + (long long)cut[lv].second]])
    next =
        mp[1][(long long)cut[lv].first * hashnum + (long long)cut[lv].second];
  else
    next =
        mp[0][(long long)cut[lv].first * hashnum + (long long)cut[lv].second];
  cut[++rec] = {next, cut[lv].second};
  make_hull(rec);
  hull[++reh] = next;
  cut[++rec] = {cut[lv].first, next};
  make_hull(rec);
  rcut[++re] =
      mpp[cut[lv].first * hashnum * hashnum + next * hashnum + cut[lv].second];
}
int main() {
  scanf("%d", &q);
  for (int u = 1; u <= q; u++) {
    scanf("%d", &n);
    for (int i = 1; i <= n - 2; i++) {
      int a, b, c;
      scanf("%d %d %d", &a, &b, &c);
      p[a] = {b, c};
      p[b] = {a, c};
      p[c] = {a, b};
      num[a]++;
      num[b]++;
      num[c]++;
      in_hash(a, b, c, i);
    }
    reh = 0;
    rec = 0;
    re = 0;
    for (int i = 1; i <= n; i++) {
      if (num[i] == 1) {
        hull[++reh] = p[i].first;
        hull[++reh] = i;
        hull[++reh] = p[i].second;
        cut[++rec] = {p[i].first, p[i].second};
        rcut[++re] =
            mpp[p[i].first * hashnum * hashnum + i * hashnum + p[i].second];
        ch[p[i].first] = true;
        ch[p[i].second] = true;
        ch[i] = true;
        break;
      }
    }
    make_hull(1);
    for (int i = 1; i <= n; i++) printf("%d ", hull[i]);
    puts("");
    for (int i = 1; i <= n - 2; i++) printf("%d ", rcut[i]);
    puts("");
    hash_clear();
    memset(ch, 0, sizeof(ch));
    memset(num, 0, sizeof(num));
  }
}
