N = int(input())
nums = list(map(int, input().split(' ')))
Q = int(input())
b, c= 1, 2
for i in range(Q):
  b, c = map(int, input().split(' '))
  if b in set(nums):
    for j, num in enumerate(nums):
      if num == b:
        nums[j] = c

  print(sum(nums))

