import bisect

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

