import java.io.*; import java.util.*; public class DeliverySystem { static int n,m,k; static boolean isC[]; static MyArrayList g[],rev[]; static ArrayList<Integer> sccCities[]; static Stack<Integer> stack; static boolean vis[]; static boolean hasC[]; static int totalSCC; static int sccID[]; static int topSortID[]; static int topStack[]; static int topID; @SuppressWarnings("unchecked") public static void main(String args[]) { InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int t = in.nextInt(); while(t-- > 0){ totalSCC = -1; topID = 0; n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); isC = new boolean[n]; for(int i=1;i<=k;i++) isC[in.nextInt() - 1] = true; g = new MyArrayList[n]; for(int i=0;i<n;i++) g[i] = new MyArrayList(); rev = new MyArrayList[n]; for(int i=0;i<n;i++) rev[i] = new MyArrayList(); while(m-- > 0){ int x = in.nextInt(); int y = in.nextInt(); x--; y--; g[x].add(y); rev[y].add(x); } sccCities = new ArrayList[n]; makeStack(); assignSCC(); /*System.out.println(totalSCC); System.out.println(Arrays.toString(sccCities)); System.out.println(Arrays.toString(hasC)); System.out.println(Arrays.toString(sccID));*/ topSort(); /*System.out.println(); System.out.println(Arrays.toString(topStack)); System.out.println(Arrays.toString(topSortID)); */ if(check()){ for(int i=totalSCC;i>=0;i--) for(int x : sccCities[topStack[i]]) if(isC[x]) w.print((x + 1) + " "); w.println(); } else w.println(-1); } w.close(); } public static boolean check(){ vis = new boolean[totalSCC + 1]; ArrayList<Integer> hasCC = new ArrayList<Integer>(); for(int i=totalSCC;i>=0;i--) if(hasC[topStack[i]]) hasCC.add(topStack[i]); int s = hasCC.size(); for(int i=0;i<s-1;i++){ int curr = hasCC.get(i); int next = hasCC.get(i + 1); vis[curr] = true; if(!enjoy(curr,next)) return false; } return true; } public static boolean enjoy(int currID,int nextID){ if(currID == nextID) return true; boolean ans = false; for(int city : sccCities[currID]){ int s = g[city].size(); for(int i=0;i<s && !ans;++i){ int next = sccID[g[city].get(i)]; if(!vis[next] && topSortID[next] <= topSortID[currID] && topSortID[next] >= topSortID[nextID]){ vis[next] = true; ans |= enjoy(next,nextID); } } } return ans; } public static void topSort(){ vis = new boolean[totalSCC + 1]; topStack = new int[totalSCC + 1]; topSortID = new int[totalSCC + 1]; for(int i=0;i<=totalSCC;i++){ if(!vis[i]){ vis[i] = true; dfs3(i); } } } public static void dfs3(int curr){ for(int city : sccCities[curr]){ int s = g[city].size(); for(int i=0;i<s;i++){ int id = sccID[g[city].get(i)]; if(!vis[id]){ vis[id] = true; dfs3(id); } } } topSortID[curr] = topID; topStack[topID++] = curr; } public static void makeStack(){ stack = new Stack<Integer>(); vis = new boolean[n]; for(int i=0;i<n;i++){ if(!vis[i]){ vis[i] = true; dfs(i); } } } public static void dfs(int curr){ int s = g[curr].size(); for(int i=0;i<s;++i){ int nxt = g[curr].get(i); if(!vis[nxt]){ vis[nxt] = true; dfs(nxt); } } stack.push(curr); } public static void assignSCC(){ vis = new boolean[n]; sccID = new int[n]; hasC = new boolean[n]; int curr; while(!stack.isEmpty()){ curr = stack.pop(); if(!vis[curr]){ totalSCC++; sccCities[totalSCC] = new ArrayList<Integer>(); vis[curr] = true; dfs2(curr); Collections.sort(sccCities[totalSCC]); } } } public static void dfs2(int curr){ if(isC[curr]) hasC[totalSCC] = true; sccID[curr] = totalSCC; sccCities[totalSCC].add(curr); int s = rev[curr].size(); for(int i=0;i<s;i++){ int nxt = rev[curr].get(i); if(!vis[nxt]){ vis[nxt] = true; sccID[nxt] = totalSCC; dfs2(nxt); } } } static public class MyArrayList { private int[] myStore; private int actSize = 0; public MyArrayList(){ myStore = new int[2]; } public int get(int index){ return myStore[index]; } public void add(int obj){ if(myStore.length-actSize <= 1) increaseListSize(); myStore[actSize++] = obj; } public int size(){ return actSize; } private void increaseListSize(){ myStore = Arrays.copyOf(myStore, myStore.length*2); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar; private int snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }