from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for q in range(Q):
    newB, newC = map(int,input().split())
    B.append(newB)
    C.append(newC)

a_dict = {}
a_dict = defaultdict(int)
for t in A:
    count = A.count(t)
    a_dict[t] = count

all_sum = sum(A)
for i in range(Q):
    diff = (C[i] - B[i]) * a_dict[B[i]]
    all_sum += diff
    a_dict[C[i]] += a_dict[B[i]]
    print(all_sum)