from collections import Counter

n = int(input())
#a,b = map(int,input().split())
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:
        #print(b,c,L[b])
        diff = (c-b) * L[b]
        all_sum = all_sum+diff
        ans_L.append(all_sum)
        L[c] += L[b]
    else:
        ans_L.append(all_sum)


L[1] += 1

for i in ans_L:
    print(i)