import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
q = int(input())
ans = []
for i in range(q):
    b, c = map(int, input().split())
    tmp = ac[b]
    del ac[b]
    ac[c]+= tmp
    ans.append(sum(num*size for num, size in ac.items()))

[print(total) for total in ans]
