import Foundation
// Decimal型の有効桁数は38桁
let N = Int(readLine()!)!
var A = readLine()!.components(separatedBy: " ").map { Int($0)! }.sorted()
let Q = Int(readLine()!)!

for _ in 1...Q {
    let line = readLine()!.components(separatedBy: " ").map { Int($0)! }
    let B = line[0]
    let C = line[1]
    
    guard let firstIndex = A.firstIndex(of: B) else {
        print(A.reduce(0) { $0 + $1 } )
        continue
    }
    guard let lastIndex = A.lastIndex(of: B) else {
        A[firstIndex] = C
        print(A.reduce(0) { $0 + $1 } )
        continue
    }
    
    for i in firstIndex...lastIndex {
        A[i] = C
    }
    print(A.reduce(0) { $0 + $1 } )
}
