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

base = sum(A)
changed = {}

Q = int(input())

for i in range(Q):
  B, C = map(int, input().split())
  # Aに現れるBの個数xがわかればよい
  x = A.count(B)
  for key, value in changed.items():
    if value == B:
      # print(f'changed {key} to {value} earlier')
      x += A.count(key)
  base += x*(C-B)
  print(base)
  changed[B] = C