//Karol Kaszuba #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; typedef double D; typedef long double LD; typedef vector<PII> VII; typedef unordered_set<int> USI; typedef unordered_set<LL> USLL; #define FOR(i,x,y) for(auto i=(x);i<=(y);++i) #define REP(i,x) FOR(i,0,(x)-1) #define FORD(i,x,y) for(auto i=(x);i>=(y);--i) #define VAR(i,c) __typeof(c) i=(c) #define FORE(i,c) for(VAR(i,(c).begin());i!=(c).end();++i) #define SIZE(c) (int)((c).size()) #define ALL(c) (c).begin(),(c).end() #define PB push_back #define IN insert #define ER erase #define MP make_pair #define ST first #define ND second #define IOSYNC ios_base::sync_with_stdio(0) #define FREOPEN(f) freopen(f, "r", stdin),freopen(f, "w", stdout) const int N = 1000006; int n; VI g[N], guwno[N]; int t, in[N], low[N]; VI s, zdejmujemy; bool stacked[N]; int scc[N], scc_n; bool odw[N]; void tarjan(int u) { low[u] = in[u] = t++; s.PB(u); stacked[u] = true; for(auto v : g[u]) { if(in[v] == -1) { tarjan(v); low[u] = min(low[u], low[v]); } else { if(stacked[v]) { low[u] = min(low[u], in[v]); } } } if(low[u] == in[u]) { while(true) { int v = s.back(); zdejmujemy.PB(v); s.pop_back(); stacked[v] = false; scc[v] = scc_n; if(v == u) { break; } } scc_n++; } } void tarjan_scc() { zdejmujemy.clear(); REP(i, n) { in[i] = low[i] = -1; scc[n] = 0; stacked[i] = false; guwno[i].clear(); odw[i] = 0; } scc_n = t = 0; REP(i, n) if(in[i] == -1) tarjan(i); } bool dfs(int a, int b) { if(a == b) return true; bool res = false; for(auto x : guwno[a]) { if(!odw[x]) { odw[x] = true; if(dfs(x, b)) res = true; } if(x == b) { res = true; } } return res; } void jebaj() { int m, k; cin >> n >> m >> k; VII cities, edges; REP(i, k) { int c; cin >> c; cities.PB(MP(c - 1, -1)); } REP(i, m) { int a, b; cin >> a >> b; a--; b--; edges.PB(MP(a, b)); g[a].PB(b); } tarjan_scc(); REP(i, n) g[i].clear(); REP(i, m) { edges[i].ST = scc[edges[i].ST]; edges[i].ND = scc[edges[i].ND]; } set<PII> srecik(ALL(edges)); for(auto x : srecik) { if(x.ST != x.ND) { guwno[x.ST].PB(x.ND); } } set<int> secik; REP(i, k) { cities[i].ND = scc[cities[i].ST]; secik.IN(cities[i].ND); } VI lel(ALL(secik)); FOR(i, 1, SIZE(lel) - 1) { odw[lel[i]] = true; if(!dfs(lel[i], lel[i - 1])) { cout << "-1\n"; return; } } sort(ALL(cities), [](const PII &a, const PII &b) -> bool {if(a.ND == b.ND) {return a.ST < b.ST;} return a.ND > b.ND;}); for(auto x : cities) cout << x.ST + 1 << " "; cout << "\n"; } int main() { IOSYNC; int t = 1; cin >> t; REP(i, t) { jebaj(); } }