#include <cstdio> #include <algorithm> #include <vector> #include <stack> using namespace std; int N,M,K,counter,sccs; vector<int> adj[100013]; vector<int> adjS[100013]; int num[100013]; int low[100013]; int visited[100013]; stack<int> scc; int which[100013]; void dfs(int x) { num[x] = low[x] = counter++; scc.push(x); for (int i: adj[x]) { if (!num[i]) dfs(i); if (low[i]) low[x] = min(low[x],low[i]); } if (low[x]==num[x]) { int cur = 0; while (true) { int v = scc.top(); scc.pop(); low[v] = 0; which[v] = sccs; cur+=1; if (x==v) break; } sccs+=1; } } vector<int> impt; vector<int> has[100013]; vector<int> topo; int where[100013]; int can[100013]; int late[100013]; void dfs2(int x) { visited[x] = 1; for (int i: adjS[x]) if (!visited[i]) dfs2(i); where[x] = topo.size(); topo.push_back(x); } void process(int x) { late[x] = -1; for (int i: adjS[x]) late[x] = max(late[x],late[i]); for (int i: adjS[x]) if (late[i]==late[x]) { can[x] = can[i]; break; } if (has[x].size()>0) { can[x]+=has[x].size(); late[x] = where[x]; } } int main() { int T; scanf("%d",&T); for (int t=0;t<T;t++) { for (int i=0;i<100013;i++) { adj[i].clear(); adjS[i].clear(); has[i].clear(); num[i] = low[i] = which[i] = visited[i] = where[i] = can[i] = late[i] = 0; } impt.clear(); topo.clear(); scanf("%d%d%d",&N,&M,&K); for (int i=0;i<K;i++) { int x; scanf("%d",&x); impt.push_back(x); } for (int i=0;i<M;i++) { int a,b; scanf("%d%d",&a,&b); adj[a].push_back(b); } counter = 1; sccs = 0; for (int i=1;i<=N;i++) if (!num[i]) dfs(i); for (int i=1;i<=N;i++) for (int j: adj[i]) if (which[i]!=which[j]) { adjS[which[j]].push_back(which[i]); } for (int i=0;i<sccs;i++) if (!visited[i]) dfs2(i); for (int i: impt) has[which[i]].push_back(i); for (int i=0;i<sccs;i++) sort(has[i].begin(),has[i].end()); for (int i: topo) process(i); vector<int> ans; for (int i: topo) for (int j: has[i]) ans.push_back(j); int ok = 0; for (int i=0;i<sccs;i++) if (can[i]==K) ok = 1; if (ok) { for (int i: ans) printf("%d ",i); printf("\n"); } else printf("-1\n"); } return 0; }