<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));
fscanf(STDIN, "%d", $q);

foreach ($a as $key => $num) {
    $a[$key] = (integer) $num;
}

$total = array_sum($a);

for ($i = 0; $i < $q; $i++) {
    fscanf(STDIN, "%d %d", $b, $c);

    if (!in_array((integer) $b, $a, true)) {
        echo "{$total}\n";
        continue;
    }

    while (in_array((integer) $b, $a, true)) {
        $key = array_search((integer) $b, $a);
        $a[$key] = $c;
    }

    $total = array_sum($a);
    echo "{$total}\n";
}
