import collections
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    input_q = list(map(int, input().split()))
    B.append(input_q[0])
    C.append(input_q[1])
    
A_sum = sum(A)
CONST_MAX = 100000
count_list = [0] * CONST_MAX

# for i in range(CONST_MAX):
#     count_list[i] = A.count(i)
c = collections.Counter(A)
for k, v in c.items():
    # print(k, v)
    count_list[k] = v


for i in range(Q):
    count_list[C[i]] += count_list[B[i]]
    A_sum += (C[i] - B[i]) * count_list[B[i]]
    count_list[B[i]] = 0
    # print(count_list)

    print(A_sum)
