#include <cassert> #include <cstdio> #include <iostream> #include <sstream> #include <numeric> #include <bitset> #include <vector> #include <set> #include <string> #include <map> #include <cmath> #include <algorithm> #include <queue> #include <cstdlib> #include <functional> #include <cstring> #include <ctime> #include <memory.h> #define y1 AAA_BBB #define y0 AAA_AAA #define pb push_back #define mp make_pair #define fi first #define se second #define forn(i, n) for(int i = 0; i < (int)(n); ++i) #define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i) #define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i) #define for1(i, n) for(int i = 1; i <= (int)(n); ++i) #define all(v) (v).begin(), (v).end() using namespace std; typedef long long i64; typedef unsigned long long u64; typedef long double ld; typedef vector<int> vi; typedef vector<i64> vi64; typedef pair<int, int> pii; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef vector<vi64> vvi64; template <class T> T inline sqr(T x) { return x * x; } const ld pi = 3.1415926535897932384626433832795; const ld eps = 1e-8; vector<char> sel; vvi g, gr; vi used; vi order; vi comp; void dfs1(int v) { used[v] = 1; for (int to: g[v]) if (!used[to]) dfs1(to); order.pb(v); } void dfs2(int v) { used[v] = 1; comp.pb(v); for (int to: gr[v]) if (!used[to]) dfs2(to); } vvi tt; void dfsc(int v, int mx) { used[v] = 1; for (int to: tt[v]) if (to <= mx && !used[to]) dfsc(to, mx); } void solve() { int n, m, k; cin >> n >> m >> k; sel.assign(n, 0); g.assign(n, vi()); gr.assign(n, vi()); forn (i, k) { int v; cin >> v; --v; sel[v] = 1; } forn (i, m) { int u, v; cin >> u >> v; --u, --v; g[u].pb(v); gr[v].pb(u); } used.assign(n, 0); order.clear(); forn (i, n) if (!used[i]) dfs1(i); used.assign(n, 0); vi ans; vi nums(n, 0); int Z = 0; vector<int> scomps; forn(i, n) { int v = order[n - 1 - i]; if (!used[v]) { dfs2(v); for (int u: comp) nums[u] = Z; vi cur; bool was = false; for (int u: comp) if (sel[u]) cur.pb(u), was = 1; if (was) scomps.pb(Z); sort(all(cur)); //reverse(all(cur)); for (int u: cur) ans.pb(u); comp.clear(); Z++; } } //cerr << "!"; //forn (i, n) cerr << nums[i] << " "; tt.assign(Z, vi()); forn (i, n) for (int to: g[i]) tt[nums[i]].pb(nums[to]); used.assign(Z, 0); used[scomps[0]] = 1; bool ok = true; forn (i, scomps.size() - 1) { dfsc(scomps[i], scomps[i + 1]); if (!used[scomps[i + 1]]) { ok = false; break; } } if (!ok) { cout << -1 << "\n"; return; } //reverse(all(ans)); for (int v: ans) cout << 1+v << " "; cout << "\n"; } int main() { #ifdef HOME freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(false); int T; cin >> T; forn (t, T) solve(); return 0; }