#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <set>
#include <algorithm>
#include <deque>
#include <list>
#include <bits/stdc++.h>
#include <queue>
using namespace std;
#define ll long long
void solve(){
int m;
cin>>m;
vector<int>ans;
vector<vector<int>>ref(m, vector<int>());
for(int i=0; i<m; i++){
int n;
cin>>n;
for(int j=0; j<n; j++){
int x;
ref[i].push_back(x);
}
}
unordered_set<int>waste;
for(int i = m-1; i>=0; i--){
int flag = 0;
for(auto a: ref[i]){
if(!flag and waste.count(a)==0){
flag = true;
ans.push_back(a);
}
waste.insert(a);
}
}
if(ans.size()==m){
for(int i=m-1; i>=0; i--){
if(i==0){
cout<<ans[i]<<endl;
}
else{
cout<<ans[i]<<" ";
}
}
}
else{
cout<<-1<<endl;
}
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8bWF0aC5oPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDxsaXN0PgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGUgPHF1ZXVlPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGxsIGxvbmcgbG9uZwoKdm9pZCBzb2x2ZSgpewogICAgaW50IG07CiAgICBjaW4+Pm07CiAgICB2ZWN0b3I8aW50PmFuczsKICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj5yZWYobSwgdmVjdG9yPGludD4oKSk7CiAgICBmb3IoaW50IGk9MDsgaTxtOyBpKyspewogICAgICAgIGludCBuOwogICAgICAgIGNpbj4+bjsKICAgICAgICBmb3IoaW50IGo9MDsgajxuOyBqKyspewogICAgICAgICAgICBpbnQgeDsKICAgICAgICAgICAgcmVmW2ldLnB1c2hfYmFjayh4KTsKICAgICAgICB9CiAgICB9CiAgICB1bm9yZGVyZWRfc2V0PGludD53YXN0ZTsKICAgIGZvcihpbnQgaSA9IG0tMTsgaT49MDsgaS0tKXsKICAgICAgICBpbnQgZmxhZyA9IDA7CiAgICAgICAgZm9yKGF1dG8gYTogcmVmW2ldKXsKICAgICAgICAgICAgaWYoIWZsYWcgYW5kIHdhc3RlLmNvdW50KGEpPT0wKXsKICAgICAgICAgICAgICAgIGZsYWcgPSB0cnVlOwogICAgICAgICAgICAgICAgYW5zLnB1c2hfYmFjayhhKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB3YXN0ZS5pbnNlcnQoYSk7CiAgICAgICAgfQogICAgfQogICAgaWYoYW5zLnNpemUoKT09bSl7CiAgICAgICAgZm9yKGludCBpPW0tMTsgaT49MDsgaS0tKXsKICAgICAgICAgICAgaWYoaT09MCl7CiAgICAgICAgICAgICAgICBjb3V0PDxhbnNbaV08PGVuZGw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIGNvdXQ8PGFuc1tpXTw8IiAiOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgZWxzZXsKICAgICAgICBjb3V0PDwtMTw8ZW5kbDsKICAgIH0KfQoKaW50IG1haW4oKXsKICAgIGludCB0OwogICAgY2luPj50OwogICAgd2hpbGUodC0tKXsKICAgICAgICBzb2x2ZSgpOwogICAgfQp9