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

for i in range(Q):
  B,C = map(int,input().split())
  M = A.count(B)
  S -= M*B
  S += M*C
  A = [i for i in A if i != "B"]
  A = A + [C]*M
  print(S)