n = int(input())
a = list(map(int, input().split()))
q = int(input())
b, c = [0] * q, [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

sum = 0
kazu = [0] * (10**5)
for i in a:
    kazu[i] += 1
    sum += i
for i in range(q):
    cnt = kazu[b[i]]
    kazu[b[i]] = 0
    kazu[c[i]] += cnt
    sa = c[i] - b[i]
    sum += (sa * cnt)
    print(sum)