import bisect

N = int(input())
A = list(map(int,input().split()))

Q = int(input())

for i in range(Q):
  x,y = map(int,input().split())
  search = x
  A.sort()
  b=bisect.bisect_left(A,search)
  c=bisect.bisect_right(A,search)
  for j in range(b,c):
    A[j] = y
  print(sum(A))

