N = int(input())
a = list(map(int,input().split()))
Q = int(input())
bc = [[int(i) for i in input().split()] for j in range(Q)]

counter = [0] * 100000
for i in a:
    counter[i] += 1

ans = sum(a)

for _ in bc:
    ans = ans + counter[_[0]] * _[1] - counter[_[0]] * _[0]
    counter[_[1]] += counter[_[0]]
    counter[_[0]] = 0
    print(ans)
