import collections

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

bc = [map(int, input().split()) for _ in range(Q)]
b, c= [list(i) for i in zip(*bc)]

count = collections.Counter(A)
# count.append([0] * 10)
sumA = sum(A)

for iter in range(Q):
    sumA += count[b[iter]]*(c[iter]- b[iter])
    c_tmp = count[c[iter]]
    count[c[iter]] += count[b[iter]] 
    count[b[iter]] -= c_tmp
    print(sumA)



