nb=int(input())
liste = [int(x) for x in input().split()]
nba = int(input())
somme = sum(liste)
for loop in range(nba):
  n,r = map(int,input().split())
  roger = liste.count(n)
  for loop in range(roger):
    liste.append(r)
  diff = r-n
  somme += diff * roger
  print(somme)