from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))

ans = sum(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    v = a[b]
    a[c] += v
    a[b] = 0
    ans += (c - b) * v
    print(ans)
