n = int(input())
arr = list(map(int, input().split()))
q = int(input())
bc = []
for i in range(0, q):
  bc.append(list(map(int, input().split())))
for j in bc:
  if j[0] in arr:
    count = arr.count(j[0])
    for _ in range(0, count):
      ind = arr.index(j[0])
      arr[ind] = j[1]
  print(sum(arr))
