import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
q=int(input())
ans=sum(a)
for _ in range(q):
  b,c=map(int,input().split())
  i=bisect.bisect_left(a,b)
  j=bisect.bisect_right(a,b)
  k=j-i
  ans=(c-b)*k+ans
  print(ans)
  a=sorted(a[:i]+a[j:]+[c]*k)