# coding: utf-8 def swap(l, x, y): x -= 1 y -= 1 buf = l[x] l[x] = l[y] l[y] = buf N, K, X = map(int, input().split(" ")) cup_list = list(range(N)) swap_list_a = [] swap_list_b = [] for i in range(1, K + 1): if i == X: input() continue elif i < X: swap_list_a.append(list(map(int, input().split(" ")))) else: swap_list_b.append(list(map(int, input().split(" ")))) swap_list_b.reverse() final_cup_list = list(map(lambda s:int(s)-1, input().split(" "))) for s in swap_list_a: swap(cup_list, s[0], s[1]) for s in swap_list_b: swap(final_cup_list, s[0], s[1]) s = [] for i in range(N): if cup_list[i] != final_cup_list[i]: s.append(i + 1) print("{} {}".format(s[0], s[1]))