from collections import Counter
n = int(input())
A = input().split()
q = int(input())
dict_A = Counter(A)
sum_list = 0
for key, value in dict_A.items():
        sum_list += int(key) * value

for i in range(q):
    b, c = map(int, input().split())
    if str(b) not in dict_A:
        print(sum_list)
    else:
        dict_A[str(c)] += dict_A[str(b)]
        dict_A[str(b)] = 0
        sum_list = 0
        for key, value in dict_A.items():
            sum_list += int(key) * value
        print(sum_list)