n = int(input())
a = [int(i) for i in input().split()]
q = int(input())

replace = []
for _ in range(q):
  m, n = [int(i) for i in input().split()]
  replace.append((m,n))

l = len(a)
res = sum(a)
for r in replace:
  for i in range(l): 
    if a[i] == r[0]:
      res += r[1] - r[0]
      a[i] = r[1]
  print(res)