'use strict';

function Main(input) {
    // N
    // A1 A2 A3...An
    // Q
    // B1 C1
    // B2 C2
    // ...
    // BQ CQ
    let tmp = input.trim().split('\n');
    const N = Number(tmp[0]);
    let A = tmp[1].split(' ').map((v) => BigInt(v));
    const Q = Number(tmp[2]);
    const BC = tmp.splice(3).map(v => v.split(' ').map(v => BigInt(v)));
    console.log(N, A, Q, BC);

    // 初期の合計
    let result = A.reduce((sum, v) => sum + v);

    // 差分
    for (let i = 0; i < Q; i++) {
        const len = A.filter(v => v === BC[i][0]).length;
        const diff = (BC[i][1] - BC[i][0]) * BigInt(len);
        result += diff;
        console.log(String(result));
        A = A.map(v => {
            if (v === BC[i][0]) {
                return BC[i][1]
            } else {
                return v;
            }
        });
    }

    return;
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));