n = int(input())
a = list(map(int, input().split()))
q = int(input())
operation = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
  a = [operation[i][1] if num == operation[i][0] else num for num in a]
  print(sum(a))