#include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(a) (int)a.size() #define fs first #define sc second typedef long long ll; typedef pair<int,int> ii; const int N = 300005; int d[N], n, m, k, st[N],low[N],num[N], cnt, SL, color[N], a[N], F[N], k2; bool ok[N], visit[N]; vector<int>adj[N],adj2[N],TPLT[N]; map<ii,bool> check; struct gt { int x, y; gt(int _x=0, int _y=0) { x = _x; y = _y; } }; gt e[N]; struct cmp { bool operator() (gt u, gt v) { if (u.x != v.x) return u.x < v.x; return u.y < v.y; } }; set<gt,cmp> s; void dfs(int u) { num[u] = low[u] = ++cnt; st[++st[0]] = u; for (int i = 0; i < sz(adj[u]); ++i) { int v = adj[u][i]; if (visit[v]) continue; if (num[v]) low[u] = min(low[u],num[v]); else { dfs(v); low[u] = min(low[u],low[v]); } } if (low[u]==num[u]) { ++SL; while (st[st[0]]!=u) { if (ok[st[st[0]]]) TPLT[SL].pb(st[st[0]]); color[st[st[0]]] = SL; visit[st[st[0]]] = true; st[0]--; } if (ok[u]) TPLT[SL].pb(u); TPLT[SL].pb(n+1); sort(TPLT[SL].begin(),TPLT[SL].end()); k2 += (TPLT[SL][0] != n+1); color[u] = SL; visit[u] = true; st[0]--; } } int main() { //freopen("input.txt","r",stdin); int t; scanf("%d",&t); while (t--) { scanf("%d%d%d",&n,&m,&k); k2 = 0; for (int i = 1; i <= n; ++i) ok[i]=false, F[i] = 0,adj[i].clear(), d[i] = 0, adj2[i].clear(), TPLT[i].clear(), visit[i] = false, num[i] = low[i] = 0; check.clear(); for (int i = 1; i <= k; ++i) scanf("%d",&a[i]), ok[a[i]] = true; for (int i = 1; i <= m; ++i) { scanf("%d%d",&e[i].x,&e[i].y); adj[e[i].x].pb(e[i].y); } ///////////// cnt = 0; st[0] = 0, SL = 0; for (int i = 1; i <= n; ++i) if (!num[i]) dfs(i); ///////////// for (int i = 1; i <= m; ++i) { if (color[e[i].x] != color[e[i].y] && !check[ii(color[e[i].x],color[e[i].y])]) { adj2[color[e[i].x]].pb(color[e[i].y]); check[ii(color[e[i].x],color[e[i].y])] = true; d[color[e[i].y]]++; } } ///////////// for (int i = 1; i <= SL; ++i) if (!d[i]) s.insert(gt(TPLT[i][0],i)); st[0] = 0; while (!s.empty()) { gt u = *s.begin(); st[++st[0]] = u.y; s.erase(u); for (int i = 0; i < sz(adj2[u.y]); ++i) { int v = adj2[u.y][i]; d[v]--; if (d[v]==0) s.insert(gt(TPLT[v][0],v)); } } for (int i = st[0]; i >= 1; --i) { for (int j = 0; j < sz(adj2[st[i]]); ++j) F[st[i]] = max(F[st[i]],F[adj2[st[i]][j]]); F[st[i]] += (TPLT[st[i]][0]!=n+1); } bool kiemtra = false; for (int i = 1; i <= st[0]; ++i) if (F[st[i]]==k2) { kiemtra = true; break; } if (!kiemtra) { printf("-1\n"); continue; } for (int i = 1; i <= st[0]; ++i) if (TPLT[st[i]][0] != n+1) { for (int j = 0; j < sz(TPLT[st[i]])-1; ++j) printf("%d ",TPLT[st[i]][j]); } printf("\n"); } return 0; }