#include <bits/stdc++.h>
using namespace std;
const int MODULO = 1e9 + 7;
const char SPACE = ' ', ENDL = '\n';
int ri() {
  int v;
  cin >> v;
  return v;
}
long long rll() {
  long long v;
  cin >> v;
  return v;
}
vector<int> rvi(int n) {
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  return a;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tests = ri();
  bool fourth = false;
  for (int t = 0; t < tests; ++t) {
    int n = ri();
    vector<vector<int> > a(n - 1, vector<int>());
    for (int i = 0; i < n - 1; ++i) {
      int sz = ri();
      a[i] = rvi(sz);
    }
    vector<vector<int> > in(n - 1, vector<int>(n + 1, false));
    for (int i = 0; i < a.size(); ++i) {
      for (int v : a[i]) in[i][v] = true;
    }
    vector<int> oc(n + 1, 0);
    for (auto& row : a) {
      for (int v : row) {
        oc[v]++;
      }
    }
    vector<int> pl;
    for (int i = 1; i <= n; ++i) {
      if (oc[i] == 1) {
        pl.push_back(i);
      }
    }
    vector<int> ans(n, 0);
    for (int last : pl) {
      vector<int> cnts(oc.begin(), oc.end());
      vector<int> used(n - 1, false);
      ans.assign(n, -1);
      bool fail = false;
      vector<int> pc;
      pc.push_back(last);
      for (int j = n - 1; j >= 1; --j) {
        int cur = -1;
        for (int v : pc) {
          if (cnts[v] == 1) {
            if (cur == -1 || oc[cur] < oc[v]) cur = v;
          }
        }
        ans[j] = cur;
        if (ans[j] == -1) {
          fail = true;
          break;
        }
        pc.clear();
        for (int i = 0; i < n - 1; ++i) {
          if (!used[i] && in[i][ans[j]]) {
            for (int v : a[i]) {
              cnts[v]--;
              if (cnts[v] == 1) pc.push_back(v);
            }
            used[i] = true;
          }
        }
      }
      for (int v = 1; v <= n; ++v) {
        if (find(ans.begin(), ans.end(), v) == ans.end()) {
          ans[0] = v;
          break;
        }
      }
      if (!fail) break;
    }
    for (int v : ans) {
      cout << v << SPACE;
    }
    cout << ENDL;
  }
  return 0;
}
