N = int(input())
A = input().split(' ')
Q = int(input())
bc = [input().split() for _ in range(Q)]
A = [int(i) for i in A]
for i in range(Q):
    bc[i] = [int(j) for j in bc[i]]

ans = sum(A)
counter = 0
# print('-input end-')
# print(ans)
# print('=sum=')

for i in range(Q):
    # print('+++++++')
    # print(A)
    # print('+++++++')
    for j in range(N):
        if A[j] == bc[i][0]:
            A[j] = bc[i][1]
            counter = counter + 1
            # print('dif : ' + str(bc[i][1] - bc[i][0]))
            # print('counter : ' + str(counter))
    ans += counter*(bc[i][1] - bc[i][0])
    print(ans)
    counter = 0
