n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = list(map(int, input().split()) for _ in range(q))

num = [0]*(10**5 + 1)
for i in range(10**5 + 1):
    num[i] = a.count(i)

s = sum(a)

for b, c in bc:
    s += (c - b)*num[b]
    num[c] += num[b]
    num[b] = 0

    print(s)