from collections import Counter
N = int(input())
A_list = list(map(int, input().split()))
Q = int(input())
BC_list = [list(map(int, input().split())) for i in range(Q)]

count_list = [0 for i in range(10**5 + 1)]
for a, i in Counter(A_list).items():
    count_list[a] = i

for b, c in BC_list:
    count_list[c] += count_list[b]
    count_list[b] = 0
    _sum = 0
    for i, a in enumerate(count_list):
        _sum += i * a
    print(_sum)