#数字の個数
N = int(input())

A = list(map(int,input().split()))

#操作の回数
Q = int(input())

B = []
C = []

set = (set(A)) #存在する数字のリスト

#数値nの個数を追加
nums = {}
for n in list(set):
    nums[n] = A.count(n)

S = sum(A)

for _ in range(Q):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)


for i in range(Q):
    b = B[i]
    c = C[i]

    if b in nums:
        Bnum = nums[b]
        S += (c-b)*Bnum

        if c in nums:
            nums[c] += Bnum

        else:
            nums[c] = Bnum

        del nums[b]
    print(S)