#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  void solve(int n, vector<vector<int>>& R, vector<int>& P, vector<int>& ord) {
    P.clear();
    ord.clear();
    map<pair<int, int>, vector<int>> M;
    for (int i = 0; i < R.size(); ++i) {
      int m = R[i].size();
      for (int j = 0; j < m; ++j) {
        for (int k = j + 1; k < m; ++k) {
          int a = R[i][j];
          int b = R[i][k];
          if (a > b) {
            swap(a, b);
          }
          M[make_pair(a, b)].push_back(i);
        }
      }
    }
    vector<vector<int>> graph(n);
    int beg = -1;
    for (auto& P : M) {
      if (P.second.size() == 1) {
        int u = P.first.first;
        int v = P.first.second;
        graph[u].push_back(v);
        graph[v].push_back(u);
        if (beg == -1) {
          beg = u;
        }
      }
    }
    vector<bool> visited(n, false);
    {
      int u = beg;
      int p = -1;
      while (!visited[u]) {
        visited[u] = true;
        P.push_back(u);
        for (auto v : graph[u]) {
          if (p != v) {
            p = u;
            u = v;
            break;
          }
        }
      }
    }
    int m = R.size();
    vector<int> cnts(m, 3);
    for (auto& P : M) {
      if (P.second.size() == 1) {
        int x = P.second[0];
        cnts[x] -= 1;
      }
    }
    for (int i = 0; i < m; ++i) {
      if (cnts[i] <= 1) {
        ord.push_back(i);
      }
    }
    for (int i = 0; i < ord.size(); ++i) {
      int u = ord[i];
      auto& T = R[u];
      for (int j = 0; j < T.size(); ++j) {
        for (int k = j + 1; k < T.size(); ++k) {
          int a = T[j], b = T[k];
          if (a > b) {
            swap(a, b);
          }
          for (auto& v : M[make_pair(a, b)]) {
            if (v != u) {
              if (--cnts[v] == 1) {
                ord.push_back(v);
              }
            }
          }
        }
      }
    }
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int t;
  cin >> t;
  while (t-- > 0) {
    int n;
    cin >> n;
    vector<vector<int>> R;
    for (int i = 0; i < n - 2; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      --a, --b, --c;
      R.emplace_back(vector<int>{a, b, c});
    }
    vector<int> P;
    vector<int> ord;
    sol.solve(n, R, P, ord);
    for (int i = 0; i < n; ++i) {
      cout << P[i] + 1 << (i == n - 1 ? '\n' : ' ');
    }
    for (int i = 0; i < ord.size(); ++i) {
      cout << ord[i] + 1 << (i + 1 == ord.size() ? '\n' : ' ');
    }
  }
  return 0;
}
