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 readLinesBC(times: Int) -> [[Int]] {
    var array = [[Int]]()
    for _ in 0..<times {
        array.append(readSeparatedInts())
    }
    return array
}


let N = readInt()

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


for q in 0..<Q {
    var _numbers = [Int]()
    var s: Int = 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(s)
    numbers = _numbers
}

