n = int(input())
a = list(map(int, input().split()))
q = int(input())
s = [list(map(int, input().split())) for i in range(q)]

ans = sum(a)
from collections import Counter
cnt = Counter(a)

for i, j in s:
    
    if j in cnt:
        cnt[j] += cnt[i]
    else:
        cnt[j] = cnt[i]
        
    ans = ans - i * cnt[i] + cnt[i] * j
    cnt.pop(i)

    print(ans)