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: # -*- coding: utf-8 -*-
  
  
  def cal_xor(xor_list, rm_ind):
      ans = None
      for i, xi in enumerate(xor_list):
          if i != rm_ind:
              if ans is not None:
                  ans = ans ^ xi
              else:
                  ans = xi
      return ans
  
  
  (N,) = map(int, input().split())
  a = list(map(int, input().split()))
  
  ans_str = ""
  
  if N == 2:
      print("{} {}".format(a[1], a[0]))
  else:
  
      xors = []
      for i in range(N // 2):
          xors.append(a[2 * i] ^ a[2 * i + 1])
  
      for i, ai in enumerate(a):
          sum_xor = cal_xor(xors, i // 2)
          if i % 2 == 0:
              ind = i + 1
          else:
              ind = i - 1
  
          ans = sum_xor ^ a[ind]
          ans_str += str(ans) + " "
      print(ans_str[:-1])
  
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"}]