#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(20);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<vector<int>> v(n - 1);
    for (int i = 0; i < n - 1; ++i) {
      int k;
      cin >> k;
      v[i].resize(k);
      for (int j = 0; j < k; ++j) {
        cin >> v[i][j];
      }
    }
    vector<int> starts;
    {
      set<int> possible_starts;
      set<int> impossible_starts;
      for (int i = 0; i < n; ++i) {
        if (v[i].size() == 2) {
          for (int j = 0; j < 2; ++j) {
            if (impossible_starts.count(v[i][j])) {
              continue;
            } else if (possible_starts.count(v[i][j])) {
              impossible_starts.insert(v[i][j]);
              possible_starts.erase(v[i][j]);
            } else {
              possible_starts.insert(v[i][j]);
            }
          }
        }
      }
      starts.resize(possible_starts.size());
      copy(possible_starts.begin(), possible_starts.end(), starts.begin());
    }
    vector<int> correct_permutation(n);
    for (auto start : starts) {
      vector<set<int>> segs(n - 1);
      for (int i = 0; i < n - 1; ++i) {
        for (int j = 0; j < (int)v[i].size(); ++j) {
          segs[i].emplace(v[i][j]);
        }
      }
      vector<int> changed(n - 1, false);
      int i = 0;
      int now = start;
      bool wrong = false;
      while (i < n - 1) {
        correct_permutation[i++] = now;
        vector<int> ones;
        for (int j = 0; j < n - 1; ++j) {
          if (segs[j].empty()) continue;
          bool has = segs[j].count(now);
          if (changed[j] && (!has)) {
            wrong = true;
            break;
          }
          if (has) {
            changed[j] = true;
            segs[j].erase(now);
          }
          if (segs[j].size() == 1) {
            ones.push_back(j);
          }
        }
        if (ones.size() != 1) {
          wrong = true;
        } else {
          now = *segs[ones[0]].begin();
        }
        if (wrong) break;
      }
      correct_permutation[i++] = now;
      if (!wrong) break;
    }
    for (int i = 0; i < n; ++i) {
      cout << correct_permutation[i] << ' ';
    }
    cout << '\n';
  }
  return 0;
}
