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: 
  
  def main():
      n, *i = map(int, open(0).read().split())
      a = i[:n]　　＃数列Aのリスト
      _ = i[n]　　　＃Qのこと
      s = sum(a)　　＃数列Aの総和
  
      m = [0] * (10 ** 5 + 1)　　＃Aは1<A<10^5なのでラベル用リストを作成
      for x in a:　　　　　　　　　＃Aの個数をラベル化。リストmは個数を記録している
          m[x] += 1
  
      ans = []
      for b, c in zip(*[iter(i[n + 1:])] * 2):
          m[c] += m[b]　　　　　　＃ｃの個数にbの個数を足し算
          s += (c - b) * m[b]　　＃s:数列Aの総和に、(c-b)×(bの個数)を足し算
          m[b] = 0　　　　　　　　　＃bの個数はゼロに
          ans.append(s)　　　　　　＃リストansにSの変化を記録していく
  
      print("\n".join(map(str, ans)))
  
  
  if __name__ == '__main__':
      main()
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"}]