import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int x = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = i + 1; } ArrayDeque lefts = new ArrayDeque<>(); ArrayDeque rights = new ArrayDeque<>(); for (int i = 0; i < k; i++) { if (i == x - 1) { sc.next(); sc.next(); continue; } int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; if (i < x - 1) { int tmp = arr[a]; arr[a] = arr[b]; arr[b] = tmp; } else { lefts.push(a); rights.push(b); } } int[] results = new int [n]; for (int i = 0; i < n; i++) { results[i] = sc.nextInt(); } while (lefts.size() > 0) { int a = lefts.pop(); int b = rights.pop(); int tmp = results[a]; results[a] = results[b]; results[b] = tmp; } int first = 0; int second = 0; for (int i = 0; i < n; i++) { if (arr[i] != results[i]) { if (first == 0) { first = i + 1; } else { second = i + 1; } } } System.out.println(first + " " + second); } }