N = int(input())
seq = [int(x) for x in input().split()]
Q = int(input())
somme = []
for i in range(Q):
  l = [int(x) for x in input().split()]
  a = l[0]
  b = l[1]
  if a in seq:
   	e = [ b if x == a else x for x in seq]
  else:
    e = seq[:]
  somme.append(sum(e))
  seq.clear()
  seq = e[:]
  e.clear()
for i in somme:
  print(i)
I love this game