#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> m[n];
for (int i = 0; i < n; i++) {
int x;
cin >> x;
for (int j = 0; j < x; j++) {
int y;
cin >> y;
m[i].push_back(y);
}
}
bool possible[50001] = {false};
vector<int> ans;
for (int i = n - 1; i >= 0; i--) {
bool found = false;
for (auto itr : m[i]) {
if (!found && !possible[itr]) {
found = true;
possible[itr] = true;
ans.push_back(itr);
} else
possible[itr] = true;
}
}
if (ans.size() == n) {
reverse(ans.begin(), ans.end());
for (auto itr : ans)
cout << itr << " ";
} else
cout << "-1";
cout << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlICh0LS0pIHsKICAgICAgICBpbnQgbjsKICAgICAgICBjaW4gPj4gbjsKICAgICAgICB2ZWN0b3I8aW50PiBtW25dOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIGludCB4OwogICAgICAgICAgICBjaW4gPj4geDsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCB4OyBqKyspIHsKICAgICAgICAgICAgICAgIGludCB5OwogICAgICAgICAgICAgICAgY2luID4+IHk7CiAgICAgICAgICAgICAgICBtW2ldLnB1c2hfYmFjayh5KTsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgYm9vbCBwb3NzaWJsZVs1MDAwMV0gPSB7ZmFsc2V9OwogICAgICAgIHZlY3RvcjxpbnQ+IGFuczsKCiAgICAgICAgZm9yIChpbnQgaSA9IG4gLSAxOyBpID49IDA7IGktLSkgewogICAgICAgICAgICBib29sIGZvdW5kID0gZmFsc2U7CiAgICAgICAgICAgIGZvciAoYXV0byBpdHIgOiBtW2ldKSB7CiAgICAgICAgICAgICAgICBpZiAoIWZvdW5kICYmICFwb3NzaWJsZVtpdHJdKSB7CiAgICAgICAgICAgICAgICAgICAgZm91bmQgPSB0cnVlOwogICAgICAgICAgICAgICAgICAgIHBvc3NpYmxlW2l0cl0gPSB0cnVlOwogICAgICAgICAgICAgICAgICAgIGFucy5wdXNoX2JhY2soaXRyKTsKICAgICAgICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICAgICAgICAgIHBvc3NpYmxlW2l0cl0gPSB0cnVlOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBpZiAoYW5zLnNpemUoKSA9PSBuKSB7CiAgICAgICAgICAgIHJldmVyc2UoYW5zLmJlZ2luKCksIGFucy5lbmQoKSk7CiAgICAgICAgICAgIGZvciAoYXV0byBpdHIgOiBhbnMpCiAgICAgICAgICAgICAgICBjb3V0IDw8IGl0ciA8PCAiICI7CiAgICAgICAgfSBlbHNlCiAgICAgICAgICAgIGNvdXQgPDwgIi0xIjsKICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICB9Cn0K