from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
A = Counter(a).most_common()
d = [0] * 10**5
for i in range(len(A)):
    d[A[i][0]] = A[i][1]

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

for i in range(q):
    d[C[i]] += d[B[i]]
    cnt = d[B[i]]
    ans += (C[i]-B[i])*cnt
    print(ans)
    d[B[i]] = 0