n = int(input())
a = list(map(int, input().split()))
s = 0
for g in range(len(a)):
    s += a[g]
e = [0] * 10001
for i in a:
    e[i] += 1
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
for j in range(q):
    s += (bc[j][1] - bc[j][0]) * e[bc[j][0]]
    e[bc[j][1]] += e[bc[j][0]]
    e[bc[j][0]] = 0
    print(s)