N=int(input())
A=list(map(int,input().split()))

Q=int(input())
comb=[]
for i in range(Q):
    comb.append(list(map(int,input().split())))

ra=len(A)

sum_num=[0 for i in range(Q)]
for i in range(Q):
    A=[comb[i][1] if A[j]==comb[i][0] else A[j] for j in range(ra)]
    sum_num[i]=sum(A)

for i in sum_num:
    print(i)