N = int(input())
A = list(map(int, input().split()))
#A = sorted(A)
Q = int(input())

def my_index_multi(l, x):
  return [i for i, _x in enumerate(l) if _x == x]

for i in range(Q):
  BC = list(map(int, input().split()))
  B_i = BC[0]
  C_i = BC[1]
  B_ind = my_index_multi(A, B_i)
  for j in B_ind:
    A[j] = C_i
  print(sum(A))
  
  