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 = [A.count(i) for i in range(1, 100001)]
for change in changes:
    num[change[1] - 1] += num[change[0] - 1]
    num[change[0] - 1] = 0
    s = 0
    for i, c in enumerate(num):
        s += (i + 1) * c
    print(s)