N=int(input())
A=list(map(int,input().split()))
Q=int(input())
P=[]
for i in range(Q):
    a,b=input().split()
    P.append((int(a), int(b))
for j in range(len(A)):
	for i in range(i):
		if P[i]==B[j][0]:
             P[i]=B[j][1]
    print(sum(P))