import Foundation

var n = Int(readLine()!)!
var a = readLine()!.split(separator: " ").map{ Int($0)! }
var q = Int(readLine()!)!
var bc = (0..<q).map{ _ in readLine()!.split(separator: " ").map{ Int($0)! } }

for i in 0..<q {
    a = a.map{ $0 == bc[i][0] ? bc[i][1] : $0 }
    print(a.reduce(0, +))
}
