N, K, X = map(int, input().split()) c = [i for i in range(1, N + 1)] for i in range(X - 1): a, b = map(int, input().split()) c[a - 1], c[b - 1] = c[b - 1], c[a - 1] input() d = c.copy() for i in range(K - X): a, b = map(int, input().split()) c[a - 1], c[b - 1] = c[b - 1], c[a - 1] C = list(map(int, input().split())) for i in range(N): if C[i] != c[i]: ans = [d.index(c[i]) + 1, d.index(C[i]) + 1] ans.sort() print(*ans) exit()