let n = stdin.ReadLine() |> int
let a = stdin.ReadLine().Split() |> Array.map int
let q = stdin.ReadLine() |> int
let bc = 
    [| 
        for _ in 1..q -> stdin.ReadLine().Split()|>Array.map int
    |]

let execQueries (a:int[]) (bc : int[][]) =
    // 出現頻度で管理する
    let counted = 
        let array = Array.zeroCreate 10_001
        for i in a do array.[i] <- array.[i] + 1
        array
    let mutable sum = a |> Array.sum |> int64
    seq{ 
        for bcElem in bc do
            let count = counted.[bcElem.[0]]
            counted.[bcElem.[0]] <- 0
            counted.[bcElem.[1]] <- counted.[bcElem.[1]] + count
            sum <- sum + int64 (count * (bcElem.[1] - bcElem.[0]))
            yield sum 
    }

execQueries a bc |> Seq.iter stdout.WriteLine