<?php
$n = trim(fgets(STDIN));
$a = explode(" ",trim(fgets(STDIN)));
$q = trim(fgets(STDIN));
for ($i = 0;$i < $q;++$i) {
    fscanf(STDIN,"%d %d",$b,$c);
    $tmp = array_keys($a,$b);
    foreach ($tmp as $key) {
        $a[$key] = $c;
    }
    echo array_sum($a).PHP_EOL;
}