<?php
  
$n = (int) trim(fgets(STDIN));
$as = trim(fgets(STDIN));
$q = (int) trim(fgets(STDIN));

$as = explode(' ', $as);

$am = [];
foreach ($as as $a) {
  $am[$a] = ($am[$a] ?? 0) + 1;
}

$sum = 0;
foreach ($am as $a => $c) {
  $sum += $a * $c;
}

while (false !== $s = fgets(STDIN)) {
  $s = trim($s);
  if ($s === '') {
    break;
  }
  [$b, $c] = explode(' ', $s);
  $count = $am[$b] ?? 0;
  $sum = $sum + ($c * count) - ($b * $count);
  $am[$b] = 0;
  $am[$c] = ($am[$c] ?? 0) + $count;
  printf("%s\n", $sum);
}