N = int(input())
A = list(map(int, input().split()))
Q = int(input())
changes = []
for i in range(Q):
    changes.append(tuple(map(int, input().split())))

num = {i:0 for i in range(1, 100001)}
for i in A:
    num[i] += 1

for change in changes:
    num[change[1]] += num[change[0]]
    num[change[0]] = 0
    s = sum([i * c for i, c in num.items()])
    print(s)