N,K,X = map(int,input().split()) AB = [input().split() for i in range(K)] C = input().split() S = [str(i + 1) for i in range(N)] for i in range(X-1): S[int(AB[i][0])-1],S[int(AB[i][1])-1] = S[int(AB[i][1])-1],S[int(AB[i][0])-1] for i in range(K-1,X - 1,-1): C[int(AB[i][0])-1],C[int(AB[i][1])-1] = C[int(AB[i][1])-1],C[int(AB[i][0])-1] ans=sorted([i+1 for i in range(N) if S[i] != C[i]]) print(ans[0],ans[1])