import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

l = [0] * (10**5 + 1)
c = collections.Counter(A)
for key in c:
    l[key] = c[key]

for i in range(Q):
    if B[i] in c:
        c[C[i]] += c[B[i]]
        c.pop(B[i])
    ans = 0
    for item in c:
        ans += item * c[item]
    print(ans)
