import sys

readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))

x = [0] * (10**5+5)
for a in A:
    x[a] += 1
s = sum(A)
Q = int(readline())
for _ in range(Q):
    b, c = map(int, readline().split())
    s += (c - b) * x[b]
    print(s)
    x[c] += x[b]
