from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [list(map(int, input().split())) for _ in range(q)]

c = Counter(a)
ans = sum(a)
for i in range(q):
    ans = ans + (b[i][1] - b[i][0])*c[b[i][0]]
    c[b[i][1]] += c[b[i][0]]
    print(ans)