from collections import Counter

n = int(input())
a = map(int, input().split())
d = Counter(a)

s = sum([k*v for k, v in d.items()])

q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    if b not in d.keys():
        print(s)
        continue
    cc = 0
    if c in d.keys():
        cc = d[c]
    d[c] = cc + d[b]
    del d[b]
    s = sum([k * v for k, v in d.items()])
    print(s)
