function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var N = parseInt(input[0],10);
    var Q = parseInt(input[2], 10);
    var vec_A = input[1].map(e => parseInt(e, 10));
    var v = Array.from({ length: 100000 }, () => 0);;
    for (i = 0; i < v.length; i ++){
        v[vec_A[i]- 1]++;
    }
    ary_bc = Array.from({ length: Q }, () => 0);
    for (var i = 0; i < Q; i++){
        ary_bc[i] = input[i+3].map(e => parseInt(e, 10));
    }
    var vec_S = Array.from({ length: Q }, () => 0);
    var S = sum(vec_A);
    var b, c;

    for (i = 0; i < Q; i++){
        b = ary_bc[i][0];
        c = ary_bc[i][1];
        S += v[b - 1] * (c - b); 
        v[c - 1] += v[b - 1]
        v[b - 1] = 0;
        vec_S[i] = 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"));
