n = int(input())
A = list(map(int,input().split()))
Q = int(input())
index = []
for i in range(Q):
  index.append(list(map(int,input().split())))

total = []
for i in range(Q):
  for s in range(n):
    if A[s]==index[i][0]:
      A[s] = index[i][1]
      print(A)
      total.append(sum(A))
      
print(total)
for k in range(Q):
  print(total[k])