a = input()
sequence_integer = [int(idx) for idx in input().split()]
num = int(input())
data = []
for idx in range(num):
  data.append([int(idx) for idx in input().split()])
for idx, jdx in data:
  sequence_integer[sequence_integer.index(idx)] = jdx
  print(sum([int(idx) for idx in sequence_integer]))