#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int a[N][3];
bool visited[N];
set<int> cn[N], con[N];
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) cn[i].clear(), visited[i] = 0, con[i].clear();
    for (int i = 0; i < n - 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        scanf("%d", &a[i][j]);
        --a[i][j];
        cn[a[i][j]].insert(i);
      }
    }
    priority_queue<pair<int, int> > pq;
    for (int i = 0; i < n; ++i) {
      int s = (int)cn[i].size();
      pq.push({-s, i});
    }
    vector<int> ord;
    while (int(ord.size()) < n - 2) {
      auto e = pq.top();
      pq.pop();
      int x = e.second;
      if (visited[x]) continue;
      visited[x] = 1;
      int id = *(cn[x].begin());
      ord.push_back(id);
      for (int j = 0; j < 3; ++j) {
        int z = a[id][j];
        cn[z].erase(id);
        int s = (int)cn[z].size();
        pq.push({-s, z});
      }
    }
    int last = ord.back();
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j)
        if (i != j) con[a[last][i]].insert(a[last][j]);
    for (int i = n - 4; i >= 0; --i) {
      int p = ord[i];
      int add = -1;
      int l = -1, r = -1;
      for (int j = 0; j < 3; ++j) {
        int x = a[p][j];
        if (con[x].size()) {
          if (l == -1)
            l = x;
          else
            r = x;
        } else
          add = x;
      }
      con[l].erase(r);
      con[r].erase(l);
      con[l].insert(add);
      con[r].insert(add);
      con[add].insert(l);
      con[add].insert(r);
    }
    int par = -1, p_id = 0;
    for (int i = 0; i < n; ++i) {
      printf("%d ", p_id + 1);
      for (int x : con[p_id]) {
        if (x != par) {
          par = p_id, p_id = x;
          break;
        }
      }
    }
    puts("");
    for (int x : ord) printf("%d ", ++x);
    puts("");
  }
  return 0;
}
