import collections

n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
b = []
c = []
for i in range(q):
    x, y = map(int, input().split())
    b.append(x)
    c.append(y)

d = collections.defaultdict(int)
for i in range(n):
    d[a[i]] += 1

s = sum(a)

for i in range(q):
    s -= b[i] * d[b[i]]
    s += c[i] * d[b[i]]
    d[c[i]] += d[b[i]]
    d[b[i]] = 0
    print(s)