from collections import Counter

N, *I = map(int, open(0).read().split())
A, Q, BC = I[:N], I[N], I[N + 1:]

C = Counter(A)
ans = sum(A)
for b, c in zip(*[iter(BC)] * 2):
    ans += (c - b) * C[b]
    C[c] += C[b]
    C[b] = 0
    print(ans)