output_description: Print Q integers S_{i} to Standard Output in the following format:
  
      
      
      S_{1}
      S_{2}
      \vdots
      S_{Q}
      
  
  Note that S_{i} may not fit into a 32-bit integer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_{1} A_{2} \cdots A_{N}
      Q
      B_{1} C_{1}
      B_{2} C_{2}
      \vdots
      B_{Q} C_{Q}
attempt: N = int(input())
  A = list(map(int, input().split()))
  n = sum(A)
  M = []
  P = []
  for _ in range(int(input())):
      B, C = map(int, input().split())
      if P.count(B) > 0:
          n = n - P.count(B) * M[P.index(B)] * (B - C)
      else:
          n = n - A.count(B) * (B - C)
      if A.count(B) > 0:
          M.append(A.count(B))
          P.append(C)
      print(n)
  
problem_description: Statement
  
  You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots,
  A_{N}.
  
  You will now successively do the following Q operations:
  
    * In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
  
  For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just
  after the i-th operation.
samples: [{"input": "4\n    1 2 3 4\n    3\n    1 2\n    3 4\n    2 4", "output": "11\n    12\n    16\n    \n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n  * 2, 2, 3, 4\n  * 2, 2, 4, 4\n  * 4, 4, 4, 4\n\n* * *"}, {"input": "4\n    1 1 1 1\n    3\n    1 2\n    2 1\n    3 5", "output": "8\n    4\n    4\n    \n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\n* * *"}, {"input": "2\n    1 2\n    3\n    1 100\n    2 100\n    100 1000", "output": "102\n    200\n    2000"}]