import numpy as np
N = int(input())
nums = np.array(list(map(int, input().split(' '))))
Q = int(input())
for i in range(Q):
  b, c = map(int, input().split(' '))
  nums[nums == b] = c
  print(np.sum(nums))

