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

q=int(input())
nums.sort()
for i in range(q):
  n1,n2=map(int,input().split())
  index=nums.index(n1)
  for i in range(nums.count(n1)):
      nums[index]=n2
      index+=1
  print(sum(nums))