import sys
readline = sys.stdin.buffer.readline

n = int(readline())
a = list(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))

s = sum(a)
for b, c in L:
  for i, v in enumerate(tuple(a)):
    if v == b:
      s -= (c - a[i])
      a[i] = c
  print(sum(a))
