from collections import Counter

n = int(input())
a_list = list(map(int, input().split()))
q = int(input())
bc_list = []
for _ in range(q):
    bc_list.append(list(map(int, input().split())))

sum_num = sum(a_list)
counter = Counter(a_list)

for i, (b, c) in enumerate(bc_list):
    sum_num = sum_num + ((c - b) * counter[b])
    counter[c] = counter[c] + counter[b]
    print(sum_num)
