import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
  a = np.where(a==bc[i][0],bc[i][1],a)
  print(np.sum(a))