"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    const Q = parseInt(arg[2].split(" ")[0]);
    const BC = arg.slice(3, Q + 3);
    
    let map = {};
    let sum = A.reduce((m,n)=>m+n);
    
    let answer = [];
    
    for(let i=0; i<N; i++) {
        if(!map[A[i]]) {
            map[A[i]] = 1;
        } else {
            map[A[i]]++;
        }
    }
    
    // console.log(JSON.stringify(map));
    // console.log(BC);

    for(let i=0; i<Q; i++) {
        const B = parseInt(BC[i].split(" ")[0]);
        const C = parseInt(BC[i].split(" ")[1]);
        
        let abs = C - B;
        
        
        if(map[B]) {
            sum += abs * map[B];
            
            if(map[C]) {
                map[C] += map[B];
            } else {
                map[C] = map[B];
            }
            
            map[B] = false;
        }
        
        answer.push(sum);
    }
    
    console.log(answer.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));