n = int(input())
a = list(map(int, input().split()))
d = set(a)
s = sum(a)
l = [0]*(10**5)
p = []
for i in d:
    l[i-1] = a.count(i)
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    s = s + l[b-1]*(c-b)
    l[c-1] += l[b-1]
    l[b-1] = 0
    p.append(s)
for i in p:
    print(i)