import bisect
import sys

def input():
  return sys.stdin.readline()

N=int(input())
A=sorted(list(map(int,input().split())))
Q=int(input())
for i in range(Q):
  b,c=map(int,input().split())
  l=bisect.bisect_left(A,b)
  r=bisect.bisect_right(A,b)
  for j in range(l,r):
    A[j]=c
  print(sum(A))
