N = int(input())
A = list(map(int, input().split()))
A.sort()
Q = int(input())
BC = []
flag = 1

for i in range(Q):
  BC.append(list(map(int, input().split())))

for i in range(Q):
  if flag == 1:
    A.sort()
    flag = 0
  
  if BC[i][0] < A[0] or A[N-1] < BC[i][0]:
    print(sum(A))
    continue
  
  for j in range(N):
    if A[j] == BC[i][0]:
      A[j] = BC[i][1]
      flag = 1
    elif A[j] > BC[i][0]:
      break

  print(sum(A))