from collections import Counter

N = int(input())
A = list(map(int, input().split()))

ttl = sum(A)
cnt = Counter(A)

Q = int(input())
for _ in range(Q):
    b, c = map(int, input().split())
    
    if b in cnt:
        occ = cnt.pop(b)
        ttl = ttl - b * occ
        cnt = cnt + Counter({c: occ})
        ttl = ttl + c * occ
    
    print(ttl)