import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readString() -> String {
    return readLine()!
}

func readLines(times: Int) -> [String] {
    var array = [String]()
    for _ in 0..<times {
        array.append(readLine()!)
    }
    return array
}

func readSeparatedStrings() -> [String] {
    return readLine()!.split(separator: " ").map({String($0)})
}

func readSeparatedInts() -> [Int] {
    return readLine()!.split(separator: " ").map({Int($0)!})
}
func readSeparatedDouble() -> [Double] {
    return readLine()!.split(separator: " ").map({Double($0)!})
}

func readLinesBC(times: Int) -> [[Double]] {
    var array = [[Double]]()
    for _ in 0..<times {
        array.append(readSeparatedDouble())
    }
    return array
}


let N = readInt()

var numbers = readSeparatedDouble()
let Q = readInt()
let BC = readLinesBC(times: Q)


for q in 0..<Q {
    var _numbers = [Double]()
    var s: Double = 0
    for n in 0..<N {
        if numbers[n] == BC[q][0] {
            _numbers.append(BC[q][1])
            s += BC[q][1]
        } else {
            _numbers.append(numbers[n])
            s += numbers[n]
        }
    }
    print(Int(s))
    numbers = _numbers
}

