#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<vector<int>> a(n - 2, vector<int>(3));
    vector<stack<int>> at(n + 1);
    for (int i = 0; i < n - 2; i++) {
      for (int j = 0; j < 3; j++) {
        cin >> a[i][j];
        at[a[i][j]].push(i);
      }
    }
    vector<int> cnt(n, 3);
    vector<list<int>::iterator> pp(n + 1);
    list<int> p;
    queue<int> qq;
    for (int i = 1; i <= n; i++) {
      if (at[i].size() == 1) {
        int id = at[i].top();
        for (int j = 0; j < 3; j++) {
          if (i == a[id][j]) continue;
          p.push_back(a[id][j]);
          pp[a[id][j]] = --p.end();
          while (!at[a[id][j]].empty()) {
            if (--cnt[at[a[id][j]].top()] == 1) {
              qq.push(at[a[id][j]].top());
            }
            at[a[id][j]].pop();
          }
        }
        break;
      }
    }
    while (!qq.empty()) {
      int id = qq.front();
      qq.pop();
      int now = -1, x = -1, y = -1;
      for (int j = 0; j < 3; j++) {
        if (!at[a[id][j]].empty())
          now = a[id][j];
        else {
          y = x;
          x = a[id][j];
        }
      }
      if (now < 0 || x < 0 || y < 0) {
        cout << now << ' ' << x << ' ' << y << '\n';
        return -1;
      }
      while (!at[now].empty()) {
        if (--cnt[at[now].top()] == 1) {
          qq.push(at[now].top());
        }
        at[now].pop();
      }
      auto it = pp[x];
      if (++it == p.end()) it = p.begin();
      if (*it == y)
        pp[now] = p.insert(it, now);
      else
        pp[now] = p.insert(pp[x], now);
    }
    vector<int> b;
    for (int x : p) {
      cout << x << ' ';
      b.push_back(x);
    }
    cout << '\n';
    cnt = vector<int>(n, 3);
    map<pair<int, int>, stack<int>> deg;
    vector<int> q;
    for (int i = 0; i < n - 2; i++) {
      pair<int, int> tmp;
      for (int j = 0; j < 3; j++) {
        tmp.first = a[i][j];
        tmp.second = a[i][(j + 1) % 3];
        if (tmp.first > tmp.second) swap(tmp.first, tmp.second);
        deg[tmp].push(i);
      }
    }
    for (int i = 0; i < n; i++) {
      pair<int, int> tmp = {b[i], b[(i + 1) % n]};
      if (tmp.first > tmp.second) swap(tmp.first, tmp.second);
      auto it = deg.lower_bound(tmp);
      while (!it->second.empty()) {
        if (--cnt[it->second.top()] == 1) {
          qq.push(it->second.top());
        }
        it->second.pop();
      }
    }
    while (!qq.empty()) {
      int id = qq.front();
      qq.pop();
      q.push_back(id);
      pair<int, int> tmp;
      for (int j = 0; j < 3; j++) {
        tmp.first = a[id][j];
        tmp.second = a[id][(j + 1) % 3];
        if (tmp.first > tmp.second) swap(tmp.first, tmp.second);
        auto it = deg.lower_bound(tmp);
        while (!it->second.empty()) {
          if (--cnt[it->second.top()] == 1) {
            qq.push(it->second.top());
          }
          it->second.pop();
        }
      }
    }
    for (int x : q) cout << x + 1 << ' ';
    cout << '\n';
  }
}
