from collections import Counter
input = raw_input
n = int(input())
As = list(map(int, input().split(" ")))
nums = [0] * (10**5+1)

counter = Counter(As)
cur_sum = sum(As)

for key, val in counter.items():
    nums[key] = val

q = int(input())
for i in range(q):
    b, c = map(int, input().split(" "))

    num1 = counter[b]
    counter[b] = 0
    counter[c] += num1

    diff = (c - b) * num1

    cur_sum += diff
    print(cur_sum)