N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
  B, C = map(int, input().split())
  count = 0
  check = True
  while check == True:
    if B in A:
      count += 1
      A.remove(B)
    else:
      check = False
  for i in range(count):
    A.append(C)
  print(sum(A))
