#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> PBDS;
bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
bool palind(string s){
int i = 0;
int j = s.size()-1;
while(i<j){
if(s[i] == s[j]){
i++;
j--;
}
else{
return false;
}
}
return true;
}
bool check(int i,int k){
if(i*(i+1) == 2*k){
return true;
}
return false;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout<<fixed; cout<<setprecision(10);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int c = 1;
map<int,int> m;
for(int i = 0;i<n;i++){
int s;
cin>>s;
for(int j =0;j<s;j++){
int a;
cin>>a;
m[a] = c;
}
c++;
}
vector<int> v(n,0);
for(auto i : m){
if(i.second <= n){
v[i.second-1] = i.first;
}
}
int b =1;
for(int i =0;i<n;i++){
if(v[i] == 0){
b = 0;
}
}
if(b == 0){
cout<<-1<<endl;
}
else{
for(int i =0;i<n;i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
}
return 0;
}
CgojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPiAKI2luY2x1ZGU8ZXh0L3BiX2RzL2Fzc29jX2NvbnRhaW5lci5ocHA+IAojaW5jbHVkZTxleHQvcGJfZHMvdHJlZV9wb2xpY3kuaHBwPiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsgCnVzaW5nIG5hbWVzcGFjZSBfX2dudV9wYmRzOyAKI2RlZmluZSBpbnQgbG9uZyBsb25nIAp0eXBlZGVmIHRyZWU8aW50LG51bGxfdHlwZSxsZXNzPGludD4scmJfdHJlZV90YWcsdHJlZV9vcmRlcl9zdGF0aXN0aWNzX25vZGVfdXBkYXRlPiBQQkRTOyAKCmJvb2wgaXNQcmltZShpbnQgbikgCnsgC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