from collections import Counter
n = int(input())
l = list(map(int, input().split()))
s = sum(l)
q = int(input())

c = Counter(l)

for i in range(q):
    b, t = map(int, input().split())
    if b not in c:
        continue
    s = s+(c[t]*t)-(c[b]*b)
    if t in c:
        c[t] += c[b]
    else:
        c[t] = c[b]
    print(s)
