parseline(str) = parse.(Int, split(str))
function Replacing()
    N = readline()
    A = parseline(readline())
    Q = parse(Int, readline())
    nums = zeros(Int, 10^5)
    ans = 0
    for a in A
        ans += a
        nums[a] += 1
    end
    BC = parseline.(data[4:end])
    ansStr = ""
    for q in 1:Q
        B, C = parseline(readline())
        ans += (C - B) * nums[B]
        nums[C] += nums[B]
        nums[B] = 0
        ansStr *= "$ans\n"
    end
    println(ansStr)
end
Replacing()