from collections import Counter
n = int(input())
A = list(map(int, input().split()))
q = int(input())
Acount = Counter(A)
Adic = dict(Acount)
# print(Adic)
s = 0
for key, value in Adic.items():
    s += key*value
for i in range(q):
    b, c = map(int, input().split())
    if not b in set(Adic.keys()):
        Adic[b] = 0
    s += (c - b) * Adic[b]
    if not c in set(Adic.keys()):
        Adic[c] = 0
    Adic[c] += Adic[b]
    Adic[b] = 0
    print(s)
