#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const long long linf = 4000000000000000000LL;
const long long inf = 1000000007;
const long double pi = 3.1415926535;
void pv(vector<int> a) {
  for (auto& x : a) cout << x << " ";
  cout << '\n';
}
void pv(vector<long long> a) {
  for (auto& x : a) cout << x << " ";
  cout << '\n';
}
void pv(vector<vector<int> > a) {
  for (int i = (0); i < (int(a.size())); ++i) {
    cout << i << '\n';
    pv(a[i]);
    cout << '\n';
  }
}
void pv(vector<vector<long long> > a) {
  for (int i = (0); i < (int(a.size())); ++i) {
    cout << i << '\n';
    pv(a[i]);
  }
  cout << '\n';
}
void pv(vector<string> a) {
  for (auto& x : a) cout << x << '\n';
  cout << '\n';
}
void setIO(string second) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (int(second.size())) {
    freopen((second + ".in").c_str(), "r", stdin);
    if (second != "test2") freopen((second + ".out").c_str(), "w", stdout);
  }
}
void solve() {
  int n;
  cin >> n;
  n -= 2;
  vector<vector<int> > a(n, vector<int>(3));
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (3); ++j) cin >> a[i][j], a[i][j]--;
  for (int i = (0); i < (n); ++i) sort(a[i].begin(), a[i].end());
  vector<vector<int> > adj(n);
  map<pair<int, int>, int> cur;
  for (int i = (0); i < (n); ++i) {
    pair<int, int> t = {a[i][0], a[i][1]};
    if (cur.count(t)) {
      adj[i].push_back(cur[t]);
      adj[cur[t]].push_back(i);
      cur.erase(t);
    } else {
      cur.insert({t, i});
    }
    t = {a[i][0], a[i][2]};
    if (cur.count(t)) {
      adj[i].push_back(cur[t]);
      adj[cur[t]].push_back(i);
      cur.erase(t);
    } else {
      cur.insert({t, i});
    }
    t = {a[i][1], a[i][2]};
    if (cur.count(t)) {
      adj[i].push_back(cur[t]);
      adj[cur[t]].push_back(i);
      cur.erase(t);
    } else {
      cur.insert({t, i});
    }
  }
  vector<vector<int> > next(n + 2);
  for (auto& x : cur) {
    next[x.first.first].push_back(x.first.second);
    next[x.first.second].push_back(x.first.first);
  }
  vector<int> ans;
  vector<int> visited(n + 2);
  int p = 0;
  visited[p] = 1;
  ans.push_back(p);
  for (int i = (0); i < (n + 1); ++i) {
    for (int j = (0); j < (2); ++j) {
      if (!visited[next[p][j]]) {
        p = next[p][j];
        break;
      }
    }
    visited[p] = 1;
    ans.push_back(p);
  }
  for (auto& x : ans) cout << x + 1 << " ";
  cout << '\n';
  vector<int> sizes(n);
  for (int i = (0); i < (n); ++i)
    for (auto& x : adj[i]) sizes[x]++;
  vector<int> todo;
  fill(visited.begin(), visited.end(), 0);
  for (int i = (0); i < (n); ++i)
    if (sizes[i] == 1 || sizes[i] == 0) {
      visited[i] = 1;
      todo.push_back(i);
    }
  while (int(todo.size())) {
    int i = todo.back();
    todo.pop_back();
    cout << i + 1 << " ";
    for (auto& x : adj[i]) {
      sizes[x]--;
      if (!visited[x] && (sizes[x] == 1 || sizes[x] == 0)) {
        visited[x] = 1;
        todo.push_back(x);
      }
    }
  }
  cout << '\n';
}
int main() {
  setIO("");
  int testc;
  cin >> testc;
  while (testc--) {
    solve();
  }
}
