from collections import Counter
n = int(input())
la = list(map(int, input().split()))
s = sum(la)
d = dict(Counter(la))

q = int(input())
for _ in range(q):
    b,c = map(int, input().split())
    nb = d.pop(b)
    delta = (c-b)*nb
    s += delta
    print(s)
    if c in d:
        d[c] += nb
    else:
        d[c] = nb