#数字の個数
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):
    if B[i] in nums:
        Bnum = nums[B[i]]
        S += (C[i]-B[i])*Bnum

        if C[i] in nums:
            nums[C[i]] += Bnum

        else:
            nums[C[i]] = Bnum

        nums[B[i]] = 0
    print(S)