import sys
input = sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
A.sort()
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  a=set(A)
  if b in a:
    k=A.count(b)
    x=A.index(b)
    f=x+k
    for i in range(x,f):
      A[i]=c
    ans=sum(A)
  print(ans)