from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
s = sum(A)
d = defaultdict(int)
for key in A:
    d[key] += 1
d[s] = s

Q = int(input())
for _ in range(Q):
    b, c = map(int, input().split())
    change_sum = d[b] * (c-b)
    d[s] += change_sum
    d[c] += d[b]
    d.pop(b)
    print(d[s])