#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
//graf csucsai
struct vertex
{
int id, group=0, indegree;
bool special=false;
vector<vertex*> inedge, outedge; //bejovo és kimeno elek
};
bool operator< (vertex a, vertex b)
{
return a.group>b.group;
}
//megtalalja, hogy melyik latvanyos csucsot kell biztosan megeloznie
void DFS(vertex &v, int group)
{
v.group=group;
for (auto u : v.inedge)
{
if ((*u).group == 0 ) DFS(*u, group);
}
}
void solve()
{
int n, k;
cin>>n>>k;
int special[k];//latvanyos csucsok
vertex vertices[n+1]; //csucsok
for (int i=1; i<=n; i++)
{
//graf beolvasasa
vertices[i].id=i;
int degree;
cin>>degree;
vertices[i].indegree=degree;
for (int j=0; j<degree; j++)
{
int neighbour;
cin>>neighbour;
vertices[i].inedge.pb(&vertices[neighbour]);
vertices[neighbour].outedge.pb(&vertices[i]);
}
}
for (int i=0; i<k; i++)
{
//specialis csucsok, a csucsok csoportositasa
cin>>special[i];
vertices[special[i]].special=true;
DFS(vertices[special[i]], i+1);
}
priority_queue<vertex> topsort; //a topologikus rendezeshez kell, masodlagos rendezes csoport alalpjan
queue<vertex> specials; //latvanyos feladatok varoja
vector<deque<vertex>> res(k);
int waittime=0, bound = (n+k-1)/k , spec=0;
//waittime: legutobbi latvanyos feladat ota eltelt ido
//bound: a maximalis varakozasi ido, spec: hany latvanyos csucs volt eddig
for (int i=1; i<=n; i++)
{
if (vertices[i].indegree==0) topsort.push(vertices[i]);
}
for (int i=0; i<n; i++)
{
waittime++;
while(!topsort.empty() && topsort.top().special) //"keszen allo" latvanyos feladatok szetszedese
{
specials.push(topsort.top());
topsort.pop();
}
//Uj elem kivalasztasa
if (waittime==bound)
{
if (specials.empty())
{
cout<<-1<<"\n";
return ;
}
vertex f = specials.front();
specials.pop();
for (auto x: f.outedge)
{
if (--(x->indegree) ==0) topsort.push(*x);
}
waittime=0;
spec++;
}
else
{
vertex f;
if (!topsort.empty())
{
f = topsort.top();
topsort.pop();
res[spec].pb(f);
}
else
{
f = specials.front();
specials.pop();
waittime=0;
spec++;
}
for (auto x: f.outedge)
{
if (--(x->indegree) ==0) topsort.push(*x);
}
}
}
//Korrekcio
set<int> nelkuloz;
for (int i=0;i<k;i++)
{
if (res[i].size()<n/k-1) nelkuloz.insert(-(i+1));
}
// for (auto x: nelkuloz) cout<<x<<"ddd\n";
for (int i = k-1; i>=0; i--)
{
while (!res[i].empty())
{
vertex val = res[i].back();
auto it = nelkuloz.lower_bound(-val.group);
//cout<<val.id<<(*it)<<val.group<<"xx\n";
if (it==nelkuloz.end() || -(*it)<=i+1) break;
if (it==nelkuloz.end() || *it==-(i+1)) break;
res[i].pop_back();
if (res[i].size()<n/k-1) nelkuloz.insert(-(i+1));
res[-(*it)-1].push_front(val);
if (res[-(*it)-1].size()>=n/k-1) nelkuloz.erase(*it);
}
}
if (nelkuloz.empty())
{
for (int i=0;i<k;i++)
{
while (!res[i].empty())
{
cout<<res[i].front().id<<" ";
res[i].pop_front();
}
cout<<special[i]<<" ";
}
}
else cout<<-1;
cout<<"\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}