N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())
BC = []

for i in range(Q):
    b, c = (int(i) for i in input().split())
    BC.append((b,c))

sums = [0] * 10001

init_sum = sum(A)
for a in A:
    sums[a] += 1

for res in BC:
    sums[res[1]] += sums[res[0]]
    init_sum += (res[1] - res[0]) * sums[res[0]]
    sums[res[0]] = 0
    print(init_sum)
    