N,K,X=map(int,input().split()) L=[i+1 for i in range(N)] for i in range(X-1): A,B=map(int,input().split()) L[A-1],L[B-1]=L[B-1],L[A-1] p=list(input()) S=[] for i in range(X,K): A,B=map(int,input().split()) S.append([A-1,B-1]) S=S[::-1] #print(S) l=list(map(int,input().split())) #print(l) for i in range(len(S)): l[S[i][0]],l[S[i][1]]=l[S[i][1]],l[S[i][0]] #print(L) #print(l) ans=[] for i in range(N): if L[i]!=l[i]: ans.append(i+1) print(ans[0],ans[1])