n = int(input())
a = list(map(int, input().split()))
q = int(input())

for i in range(q):
  b, c = map(int, input().split())
  for i in range(n):
    x = a[i]
    if b == x:
      a[i] = c
  print(sum(a))
      






