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
  for i in ais:
    sum+=int(i)
  print(sum)