import bisect

n=int(input())
a=[int(x) for x in input().rstrip().split()]
q=int(input())
a.sort()
for i in range(q):
  b,c=map(int,input().split())
  b_l=bisect.bisect_left(a,b)
  b_r=bisect.bisect_right(a,b)
  a=a[:b_l]+[c]*(b_r-b_l)+a[b_r:]
  print(sum(a))