N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
diff_BC = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
    diff_BC.append(b-c)
sum_org = sum(A)

As = sorted(list(set(A)))
# 何が何個あるかdict
As_cnt = {}
for a in As:
    As_cnt[a] = A.count(a)

for i in range(Q):
    if B[i] in As_cnt.keys():
        t = As_cnt[B[i]]
        sum_org -= t*diff_BC[i]
        if C[i] in As_cnt.keys():
            As_cnt[C[i]] += t
        else:
            As_cnt[C[i]] = t
    print(sum_org)
