import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])

q = int(input())

b_arr = []
c_arr = []
for _ in range(q):
    b, c = map(int, input().split())
    b_arr.append(b)
    c_arr.append(c)

for i in range(len(b_arr)):
    a = np.where(a == b_arr[i], c_arr[i], a)
    print(np.sum(a))
