import numpy as np

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
b, c = map(int, input().split())
BC = [b,c]
for i in range(Q - 1):
    b, c = map(int, input().split())
    BC = np.vstack((BC,[b,c]))
for i in range(Q):
    for j in range(len(A)):
        if A[j] == BC[i,0]:
            A[j] = BC[i,1]
    print(np.sum(A))
