<?php 
  $n = trim(fgets(STDIN));
  $a = explode(' ', trim(fgets(STDIN)));
  $Q = trim(fgets(STDIN));
  $count = 0;
  $c = 0;
  $ans = 0;

  while($count < $Q){
    // code...
    list($b, $c) = explode(' ',(fgets(STDIN)));
    $a = str_replace($b, $c, $a);
    foreach ($a as $value) {
      // code...
      $c = (int)$value * 100;
      $ans += $c / 100;
    }
    echo $ans;
    echo "\n";
    $count++; 
    $ans = 0;
  }