n = int(input())
nums = [int(x) for x in input().split()]
m = int(input())

for i in range(m):
      nb,nc = [int(x) for x in input().split()]
      for j in range(len(nums)):
            if nums[j] == nb:
                  nums[j] = nc
      print(sum(nums))