<?php
fscanf(STDIN, "%d", $N);
$fmt = '%d';
for ($i = 0; $i < $N; $i++) $fmt .= ' %d';
$A = fscanf(STDIN, $fmt);

fscanf(STDIN, "%d", $Q);
$B = Array();
$C = Array();
for ($i = 0; $i < $Q; $i++) {
  fscanf(STDIN, '%d %d', $tb, $tc);
  $B[] = $tb;
  $C[] = $tc;
}

$sum = array_sum($A);

for ($i = 0; $i < $Q; $i++) {
    $c = 0;
  for ($j = 0; $j < $N; $j++) {

    if ($A[$j] == $B[$i]) {
      $A[$j] = $C[$i];
      $c += 1;
    }
  }
  $sum += $c * ($C[$i] - $B[$i]);
  echo $sum . "\n";
}
