n = int(input())
la = list(map(int, input().split()))
q = int(input())
s = sum(la)
for i in range(q):
  b, c = map(int, input().split())
  count = 0
  for j in range(n):
    if la[j] == b:
      la[j] = c
      count += 1
  s -= count*(b-c)
  print(s)