n = int(input())
A = list(map(int, input().split()))
q = int(input())

total = sum(A)
dic = {}
for i in range(q):
  b, c = map(int, input().split())
  b_count = A.count(b)
  c_count = A.count(c)
  dic[c] = c_count + b_count
  if b in dic:
    b_count = dic[b]
  diff = c - b
  total += b_count*diff
  print(total)
  
  
    