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

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

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

B = []
C = []

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

#set の i 番目の数字n個数
nums = []
for n in set:
    nums.append(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):
    """
        print("i",i)
        print("set,",set)
        print("nums",nums)
        print("B",B[i],"Bnum",nums[set.index(B[i])])
        print("C",C[i],"Cnum",nums[set.index(C[i])])
        """

    if set.count(B[i]) != 0:
        Bnum = nums[set.index(B[i])]
        S += (C[i]-B[i])*Bnum
    
        if set.count(C[i]) == 0:
            set.append(C[i])
            nums.append(Bnum)
        else:
            nums[set.index(C[i])] += Bnum

        nums[set.index(B[i])] = 0
    print(S)