<?php
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$q = trim(fgets(STDIN));

for($i = 0; $i < $q; $i++){
    $p = explode(' ', trim(fgets(STDIN)));
    $b = $p[0];
    $c = $p[1];
    for($j = 0; $j < $n; $j++){
        if($arr[$j] == $b){
            $arr[$j] = $c;
        }
    }
    
    echo array_sum($arr)."\n";
} 
