const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const N = lines[0] - 0
    const A = lines[1].split(' ').map(Number)
    const Q = lines[2] - 0
    const B = []
    const C = []
    for (let i = 0; i < Q; i++) {
        const row = lines[i + 3].split(' ').map(Number)
        B[i] = row[0]
        C[i] = row[1]
    }

    const dp = []
    let sum = 0
    for (let i = 0; i < A.length; i++) {
        if (dp[A[i]]) {
            dp[A[i]]++
        } else {
            dp[A[i]] = 1
        }
        sum += A[i]
    }

    for (let i = 0; i < Q; i++) {
        if (!dp[B[i]]) {
            console.log(sum)
            continue
        }
        if (!dp[C[i]]) {
            dp[C[i]] = 0
        }
        dp[C[i]] += dp[B[i]]
        sum += (C[i] - B[i]) * dp[B[i]]
        dp[B[i]] = 0

        console.log(sum)

    }

})(input)
