n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
  a.sort()
  b, c = map(int, input().split())
  if b in a:
    d = a.count(b)
    e = a.index(b)
    for i in range(d):
      a[e+i] = c
  print(sum(a))