from collections import Counter
n = int(input())
A = list(map(int, input().split()))
q = int(input())
dict_A = Counter(A)
sum_list = sum(A)
for i in range(q):
    b, c = map(int, input().split())
    if b not in dict_A:
        print(sum_list)
    else:
        dict_A[c] += dict_A[b]
        dict_A[b] = 0
        sum_list = 0
        for key, value in dict_A.items():
            sum_list += key * value
        print(sum_list)