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 = {}
for i in A:
    if i in num:
        num[i] += 1
    else:
        num[i] = 1

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