n = int(input())
ais = list(map(str, input().split()))
q = int(input())
bcs = [list(map(int, input().split())) for i in range(q)]
for b, c in bcs:
#  new = "-".join(ais)
#  change = new.replace(str(b),str(c))
#  ais = change.split('-')
  sum = 0
  l_new = []
  for i in ais:
    if int(i)==int(b):
      sum+=int(c)
      l_new.append(int(c))
    else:
      sum+=int(i)
      l_new.append(int(i))

  ais = l_new[:]
  print(sum)