import java.io.*; import java.util.*; import java.util.List; public class Main { private static StringTokenizer st; private static BufferedReader br; private static PrintWriter out; public static long MOD = 1000000007; public static void print(Object x) { out.println(x + ""); } public static String join(Collection<?> x, String space) { if (x.size() == 0) return ""; StringBuilder sb = new StringBuilder(); boolean first = true; for (Object elt : x) { if (first) first = false; else sb.append(space); sb.append(elt); } return sb.toString(); } public static String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = br.readLine(); st = new StringTokenizer(line.trim()); } return st.nextToken(); } public static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public static long nextLong() throws IOException { return Long.parseLong(nextToken()); } public static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } public static List<Integer>[] components; public static int[] s; public static int sid; public static List<Integer>[] edges; public static int curIndex; public static int[] index; public static int[] lowlink; public static boolean[] onStack; public static int n, m; public static Set<Integer> needed; public static void tarjan() { index = new int[n]; lowlink = new int[n]; onStack = new boolean[n]; s = new int[n]; sid = 0; curIndex = 1; components = new List[n]; for (int i = 0; i < n; i++) components[i] = new ArrayList<>(); m = 0; for (int v = 0; v < n; v++) { if (index[v] == 0) { strongconnect(v); } } } public static void strongconnect(int v) { index[v] = curIndex; lowlink[v] = curIndex; curIndex += 1; s[sid++] = v; onStack[v] = true; for (int w : edges[v]) { if (index[w] == 0) { strongconnect(w); lowlink[v] = Math.min(lowlink[v], lowlink[w]); } else if (onStack[w]) { lowlink[v] = Math.min(lowlink[v], index[w]); } } if (lowlink[v] == index[v]) { List<Integer> scc = new ArrayList<Integer>(); while (true) { int w = s[--sid]; onStack[w] = false; scc.add(w); if (w == v) break; } components[m++] = scc; } } public static boolean possible(boolean[] marked) { int[] which = new int[m]; Arrays.fill(which, -1); int c = 0; for (int i = m-1; i >= 0; i--) { for (int x : components[i]) if (needed.contains(x)) { marked[i] = true; break; } if (marked[i]) { which[i] = c++; } } int[] componentOf = new int[n]; for (int i = 0; i < m; i++) for (int x : components[i]) componentOf[x] = i; Set<Integer>[] cEdges = new Set[m]; for (int i = 0; i < m; i++) cEdges[i] = new HashSet<Integer>(); for (int u = 0; u < n; u++) { for (int v : edges[u]) { int cU = componentOf[u]; int cV = componentOf[v]; cEdges[cV].add(cU); } } int[] max = new int[m]; Arrays.fill(max, -1); for (int i = m-1; i >= 0; i--) { int pr = -1; for (int x : cEdges[i]) pr = Math.max(pr, max[x]); if (marked[i] && pr+1 != which[i]) return false; pr = Math.max(pr, which[i]); max[i] = pr; } return true; } public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter (System.out, true); int T = nextInt(); for (; T > 0; T--) { n = nextInt(); int e = nextInt(); int k = nextInt(); needed = new HashSet<Integer>(); for (int i = 0; i < k; i++) needed.add(nextInt()-1); edges = new List[n]; for (int i = 0; i < n; i++) edges[i] = new ArrayList<Integer>(); for (int i = 0; i < e; i++) { int u = nextInt() - 1; int v = nextInt() - 1; edges[u].add(v); } tarjan(); List<Integer>[] neededFor = new List[m]; boolean[] marked = new boolean[m]; for (int i = m-1; i >= 0; i--) { List<Integer> cur = new ArrayList<Integer>(); for (int x : components[i]) if (needed.contains(x)) cur.add(x+1); if (cur.size() > 0) marked[i] = true; Collections.sort(cur); neededFor[i] = cur; } if (!possible(marked)) { print(-1); continue; } List<Integer> out = new ArrayList<Integer>(); for (int i = m-1; i >= 0; i--) { out.addAll(neededFor[i]); } print(join(out, " ")); } out.close(); System.exit(0); } }