#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e18;
template <typename T>
void printvector(const vector<T>& foo) {
  for (auto el : foo) cout << el << " ";
  cout << endl;
}
bool calc(vector<int>& permuration, const vector<vector<int>>& sets,
          vector<bool>& used) {
  if (permuration.size() == sets.size() + 1) {
    for (auto el : permuration) cout << el << " ";
    cout << "\n";
    return true;
  }
  if (permuration.empty()) {
    for (int i = 0; i < sets.size(); i++) {
      permuration.push_back(sets[i][0]);
      permuration.push_back(sets[i][1]);
      used[i] = true;
      if (calc(permuration, sets, used)) return true;
      swap(permuration[0], permuration[1]);
      if (calc(permuration, sets, used)) return true;
      used[i] = false;
      permuration.pop_back();
      permuration.pop_back();
    }
  }
  vector<int> last_elements;
  for (size_t next = 0; next < sets.size(); next++) {
    if (used[next]) continue;
    const auto& row = sets[next];
    if (row.size() > permuration.size() + 1) break;
    while (last_elements.size() < row.size() - 1) {
      last_elements.push_back(
          permuration[permuration.size() - last_elements.size() - 1]);
    }
    sort(last_elements.begin(), last_elements.end());
    vector<int> diff;
    set_difference(row.begin(), row.end(), last_elements.begin(),
                   last_elements.end(), back_inserter(diff));
    if (diff.size() > 1) continue;
    used[next] = true;
    permuration.push_back(diff[0]);
    if (calc(permuration, sets, used)) return true;
    used[next] = false;
    permuration.pop_back();
    return false;
  }
  return false;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    vector<vector<int>> sets(n - 1);
    for (auto& row : sets) {
      int k;
      cin >> k;
      row.resize(k);
      for (auto& el : row) cin >> el;
    }
    sort(sets.begin(), sets.end(),
         [](const vector<int>& a, const vector<int>& b) {
           return a.size() < b.size();
         });
    vector<int> permutation;
    vector<bool> used(n, false);
    calc(permutation, sets, used);
  }
  return 0;
}
