'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) => Number(v)).sort((a, b) => a - b);
    const Q = Number(tmp[2]);
    const BC = tmp.splice(3).map(v => v.split(' ').map(v => Number(v)));

    let arr = new Array(100001).fill(0);
    for (const v of A) {
        arr[v] += 1;
    }

    for (let i = 0; i < Q; i++) {
        arr[BC[i][1]] += arr[BC[i][0]];
        arr[BC[i][0]] = 0;
        const result = arr.reduce((sum, v, i) => sum += v * i);
        console.log(result);
    }

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