import java.io.PrintStream; import java.util.Scanner; public class Y429 { Scanner in; PrintStream out; int nextInt() { String s = in.next(); if (s.charAt(0) == '?') return -1; else return Integer.valueOf(s); } Y429() throws Exception { in = new Scanner(System.in); out = new PrintStream(System.out); int n = in.nextInt(), k = in.nextInt(), x = in.nextInt(); int[] a = new int[k], b = new int[k], c = new int[n], d = new int[n]; for (int i = 0; i < k; i++) { a[i] = nextInt(); b[i] = nextInt(); } for (int i = 0; i < n; i++) { d[i] = i + 1; c[i] = nextInt(); } for (int i = 0; i < x - 1; i++) { int tmp = d[a[i] - 1]; d[a[i] - 1] = d[b[i] - 1]; d[b[i] - 1] = tmp; } for (int i = k-1; i>x - 1; i--) { int tmp = c[a[i] - 1]; c[a[i] - 1] = c[b[i] - 1]; c[b[i] - 1] = tmp; } int[] ans = new int[2]; int cnt = 0; for (int i = 0; i < n; i++) { if (c[i] != d[i]) { ans[cnt++] = i + 1; } } if (ans[0] < ans[1]) out.println("" + ans[0] + " " + ans[1]); else out.println("" + ans[1] + " " + ans[0]); } public static void main(String argv[]) throws Exception { new Y429(); } }