from collections import Counter

n = int(input())
a_L = list(map(int,input().split()))

q = int(input())

L = Counter(a_L)
all_sum = sum(a_L)

ans_L = []
for i in range(q):
    b,c = map(int,input().split())
    if L[b] != 0:
        diff = (c-b) * L[b]
        all_sum = all_sum+diff
        L[c] += L[b]
    ans_L.append(all_sum)


for i in ans_L:
    print(i)