#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long z) {
  long long ret = 1;
  while (y > 0) {
    if (y & 1) ret = (ret * x) % z;
    x = (x * x) % z;
    y >>= 1;
  }
  return ret;
}
const long long N = 1e5 + 5;
vector<long long> V[N];
long long par[N];
unordered_map<long long, long long> in, inDeg, vis;
vector<long long> P, Q;
long long ed = 0;
long long find(long long x) {
  if (x == par[x]) return x;
  return par[x] = find(par[x]);
}
bool merge(long long a, long long b) {
  long long ra = find(a), rb = find(b);
  if (ra == rb) return 0;
  par[rb] = ra;
  return 1;
}
void addEdge(long long a, long long b) {
  if (!merge(a, b)) return;
  ++ed;
  V[a].push_back(b);
  V[b].push_back(a);
  inDeg[a]++;
  inDeg[b]++;
  return;
}
void dfs(long long x) {
  vis[x] = 1;
  P.push_back(x);
  for (auto u : V[x]) {
    if (!vis[u]) dfs(u);
  }
  return;
}
bool cmp(long long a, long long b) { return in[a] < in[b]; }
int main() {
  long long t;
  scanf("%lld", &t);
  while (t--) {
    ed = 0;
    long long n;
    scanf("%lld", &n);
    for (long long i = 1; i <= n; ++i) V[i].clear(), par[i] = i;
    in.clear();
    inDeg.clear();
    vis.clear();
    P.clear();
    Q.clear();
    set<pair<pair<long long, long long>, pair<long long, long long>>> sp, sq;
    map<pair<long long, long long>, set<pair<long long, long long>>> mk;
    for (long long i = 1; i <= n - 2; ++i) {
      vector<long long> A(3);
      for (long long j = 0; j <= 2; ++j) scanf("%lld", &A[j]), in[A[j]]++;
      sort((A).begin(), (A).end());
      sp.insert(make_pair(make_pair(A[0], A[1]), make_pair(A[2], i)));
      mk[make_pair(A[0], A[1])].insert(make_pair(A[2], i));
      mk[make_pair(A[0], A[2])].insert(make_pair(A[1], i));
      mk[make_pair(A[1], A[2])].insert(make_pair(A[0], i));
    }
    for (auto u : sp) {
      long long deg =
          min(in[u.first.first], min(in[u.first.second], in[u.second.first]));
      vector<long long> B(3);
      B[0] = u.first.first, B[1] = u.first.second, B[2] = u.second.first;
      sort((B).begin(), (B).end(), cmp);
      if (deg == 1) {
        sq.insert(u);
        addEdge(B[0], B[1]);
        addEdge(B[0], B[2]);
      }
    }
    long long curr = 0;
    while (!sq.empty()) {
      auto u = *sq.begin();
      sq.erase(u);
      Q.push_back(u.second.second);
      long long x = u.first.first, y = u.first.second, z = u.second.first,
                idx = u.second.second;
      vector<long long> A(3);
      A[0] = x, A[1] = y, A[2] = z;
      sort((A).begin(), (A).end());
      mk[make_pair(A[0], A[1])].erase(make_pair(A[2], idx));
      mk[make_pair(A[0], A[2])].erase(make_pair(A[1], idx));
      mk[make_pair(A[1], A[2])].erase(make_pair(A[0], idx));
      in[x]--, in[y]--, in[z]--;
      pair<pair<long long, long long>, pair<long long, long long>> aux, nx;
      long long aa = 0, bb = 0, cc = 0, fl = 0, la = 0, lb = 0, lc = 0;
      if (!in[x] && in[y] && in[z]) {
        fl = 1;
        auto pp = *mk[make_pair(y, z)].begin();
        long long a = pp.first, b = y, c = z, idx = pp.second;
        la = a, lb = b, lc = c;
        vector<long long> A(3);
        A[0] = a, A[1] = b, A[2] = c;
        sort((A).begin(), (A).end());
        nx = make_pair(make_pair(A[0], A[1]), make_pair(A[2], idx));
        if (in[y] == 1 || in[z] == 1) sq.insert(nx);
        aux = nx;
        aa = x, bb = y, cc = z;
      } else if (in[x] && !in[y] && in[z]) {
        fl = 1;
        auto pp = *mk[make_pair(x, z)].begin();
        long long a = pp.first, b = x, c = z, idx = pp.second;
        la = a, lb = b, lc = c;
        vector<long long> A(3);
        A[0] = a, A[1] = b, A[2] = c;
        sort((A).begin(), (A).end());
        nx = make_pair(make_pair(A[0], A[1]), make_pair(A[2], idx));
        if (in[x] == 1 || in[z] == 1) sq.insert(nx);
        aux = nx;
        aa = y, bb = x, cc = z;
      } else if (in[x] && in[y] && !in[z]) {
        fl = 1;
        auto pp = *mk[make_pair(x, y)].begin();
        long long a = pp.first, b = y, c = x, idx = pp.second;
        la = a, lb = b, lc = c;
        vector<long long> A(3);
        A[0] = a, A[1] = b, A[2] = c;
        sort((A).begin(), (A).end());
        nx = make_pair(make_pair(A[0], A[1]), make_pair(A[2], idx));
        if (in[x] == 1 || in[y] == 1) sq.insert(nx);
        aux = nx;
        aa = z, bb = y, cc = x;
      }
      long long iaa = in[lb], ibb = in[lc];
      if (iaa > ibb) swap(iaa, ibb);
      if (!fl) continue;
      if (fl && iaa == 1) {
        long long a = lb, b = lc, c = la, ia = in[a], ib = in[b];
        if (ia < ib)
          addEdge(a, c);
        else
          addEdge(b, c);
      }
    }
    for (long long i = 1; i <= n; ++i) {
      if (!vis[i] && inDeg[i] == 1) dfs(i);
    }
    for (auto u : P) printf("%lld ", u);
    printf("\n");
    for (auto u : Q) printf("%lld ", u);
    printf("\n");
  }
  return 0;
}
