N = int(input())
A = list(map(int,input().split()))
A.sort()
Q = int(input())


for _ in range(Q):
  b,c=map(int,input().split())
  time = A.count(b)
  if(time != 0):
    place = A.index(b)
    for i in range(time):
      A[place + i] = c
    A.sort()
  print(sum(A))