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

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

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

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

    foreach ($a as $key => $num) {
        if ((integer) $num !== (integer) $b) {
            continue;
        }

        $a[$key] = $c;
    }

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