from collections import Counter

n = int(input())
A = [int(i) for i in input().split()]
all = sum(A)

Q = int(input())
bc = [[int(i) for i in input().split()] for _ in range(Q)]

nums = dict(Counter(A).items())
for i in range(Q):
    #print(nums)
    b, c = bc[i][0], bc[i][1]
    if b in nums.keys(): all += c * nums[b] - b * nums[b]
    print(all)

    if c in nums.keys() and b in nums.keys():
        nums[c] += nums[b]
    elif b in nums.keys():
        nums[c] = nums[b]
    else:
        nums[c] = 0
    nums[b] = 0
