#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T, size_t SZ>
void pr(const array<T, SZ>& x);
template <class T>
void pr(const vector<T>& x);
template <class T>
void pr(const set<T>& x);
template <class T1, class T2>
void pr(const map<T1, T2>& x);
template <class T>
void pr(const T& x) {
  cout << x;
}
template <class Arg, class... Args>
void pr(const Arg& first, const Args&... rest) {
  pr(first);
  pr(rest...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr("{", x.first, ", ", x.second, "}");
}
template <class T>
void prContain(const T& x) {
  pr("{");
  bool fst = 1;
  for (auto& a : x) pr(!fst ? ", " : "", a), fst = 0;
  pr("}");
}
template <class T, size_t SZ>
void pr(const array<T, SZ>& x) {
  prContain(x);
}
template <class T>
void pr(const vector<T>& x) {
  prContain(x);
}
template <class T>
void pr(const set<T>& x) {
  prContain(x);
}
template <class T1, class T2>
void pr(const map<T1, T2>& x) {
  prContain(x);
}
void ps() { pr("\n"); }
template <class Arg, class... Args>
void ps(const Arg& first, const Args&... rest) {
  pr(first, " ");
  ps(rest...);
}
template <typename T>
int remin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
int remax(T& a, const T& b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
int T;
int n;
int a[100005], b[100005], c[100005];
map<pair<int, int>, vector<int>> who;
set<pair<int, pair<int, int>>> G[100005];
pair<int, int> kek[100005];
int nxt[100004];
void add(int x, int y, int i) {
  if (x > y) swap(x, y);
  who[pair<int, int>(x, y)].push_back(i);
}
int main(int argc, const char** argv) {
  scanf("%d", &T);
  for (int tt = 0; tt < T; ++tt) {
    scanf("%d", &n);
    who.clear();
    for (int i = 0; i < n - 2; ++i) {
      scanf("%d%d%d", &a[i], &b[i], &c[i]);
      --a[i], --b[i], --c[i];
      add(a[i], b[i], i);
      add(a[i], c[i], i);
      add(b[i], c[i], i);
      G[i].clear();
    }
    for (auto x : who) {
      int s = x.second.size();
      for (int i = 0; i < s; ++i) {
        for (int j = i + 1; j < s; ++j) {
          G[x.second[i]].insert(make_pair(x.second[j], x.first));
          G[x.second[j]].insert(make_pair(x.second[i], x.first));
        }
      }
    }
    set<pair<int, int>> s;
    for (int i = 0; i < n - 2; ++i) {
      s.insert(pair<int, int>(G[i].size(), i));
    }
    vector<int> order;
    while (!s.empty()) {
      auto itr = s.begin();
      s.erase(itr);
      int u = (*itr).second;
      order.push_back(u);
      for (auto [v, pr] : G[u]) {
        s.erase(pair<int, int>(G[v].size(), v));
        G[v].erase(make_pair(u, pr));
        kek[u] = pr;
        s.insert(pair<int, int>(G[v].size(), v));
      }
    }
    reverse(order.begin(), order.end());
    for (int x : order) {
      if (x == order[0]) {
        nxt[a[x]] = b[x];
        nxt[b[x]] = c[x];
        nxt[c[x]] = a[x];
      } else {
        auto [u, v] = kek[x];
        if (nxt[u] != v) swap(u, v);
        int w = a[x] ^ b[x] ^ c[x] ^ u ^ v;
        nxt[u] = w;
        nxt[w] = v;
      }
    }
    int curr = 0;
    for (int i = 0; i < n; ++i) {
      printf("%d ", nxt[curr] + 1);
      curr = nxt[curr];
    }
    printf("\n");
    reverse(order.begin(), order.end());
    for (int x : order) {
      printf("%d ", x + 1);
    }
    printf("\n");
  }
  return 0;
}
