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

result = a

l = []

for i in range(q):
  b, c = map(int, input().split())
  result = [c if j == b else j for j in result]

  # l.append(sum(result))
  print(sum(result))


# for i in l:
#   print(i)