N = int(input())
nums = list(map(int, input().split(' ')))
Q = int(input())

for i in range(Q):
  b, c = map(int, input().split(' '))
  sum_num = 0
  for j in range(len(nums)):
    if nums[j] == b:
      nums[j] = c
    sum_num += nums[j]
  print(sum_num)
 