func sReadLine() -> [String] {
    return readLine()!.characters.split(" ").map{String($0)}
}
func sReadInt() -> [Int] {
    let strs = sReadLine()
    return strs.map{Int($0)!}
}
func readInt() -> Int {
    return Int(readLine()!)!
}
/************** main *****************/
let n = readInt()
var sparr: [(String, Int)] = (1...n).map { i in
    let sp = sReadLine()
    return (sp[0], Int(sp[1])!)
}
for ssp in sparr.sort({$0.0 == $1.0 ? $0.1 > $1.1 : $0.0 < $1.0}) {
    print("\(ssp.0) \(ssp.1)")
}
