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