object Main{
	def main(args:Array[String]){
		val s = new java.util.Scanner(System.in)
		val n=s.nextInt
		val a=(1 to n).map(_=>(s.next,-s.nextInt)).toArray
		(1 to n).sortBy(i=>a(i-1)).foreach(println)
	}
}
