function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var N = parseInt(input[0],10);
    var vec_A = input[1].map(e => parseInt(e, 10));
    var Q = parseInt(input[2], 10);
    ary_bc = [];
    for (var i = 0; i < Q; i++){
        ary_bc.push(input[i+3].map(e => parseInt(e, 10)));
    }
    var　ATable = vec_A.reduce(function(m, a, i) {
        m[a] = (m[a] || []).concat(i);
        return m;
        }, {});
    var b, c, l;
    var vec_S = [];
    var S = sum(vec_A);

    for (i = 0; i < Q; i++){
        l = 0;
        if (ary_bc[i][0] in ATable){
          	l = 0;
          	var tmp = ATable[String(ary_bc[i][0])]
            if (tmp !== undefined)  l = tmp.length;
            if (ary_bc[i][1] in ATable){
                ATable[String(ary_bc[i][1])] = ATable[String(ary_bc[i][0])].concat(ATable[String(ary_bc[i][1])]);
            } else {
                ATable[String(ary_bc[i][1])] = ATable[String(ary_bc[i][0])];
            }
            delete(ATable[String(ary_bc[i][0])]);
        }
        S = S + (ary_bc[i][1] - ary_bc[i][0]) * l
        vec_S.push(S);
    }
	console.log(vec_S.join('\n');
}   

var sum  = function(arr) {
    var sum = 0;
    arr.forEach(function(elm) {
        sum += elm;
    });
    return sum;
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
