object Main extends App {
	private def func(lines: Iterator[String]) {
		//TODO scanner?

		val line = lines.zipWithIndex.map { case (e, gi) =>
			val tmp = e.split(' ')
			val p = java.lang.Integer.parseInt(tmp(0))
			val y = java.lang.Integer.parseInt(tmp(1))
			(p, (y, gi))
		}.toList

		/*
				var iii = -1
				val line = lines.map { e =>
					val tmp = e.split(' ')
					val p = java.lang.Integer.parseInt(tmp(0))
					val y = java.lang.Integer.parseInt(tmp(1))
					iii += 1
					(p, (y, iii))
				}.toList
		*/
		//val idMap = line.indices.map(_ => 0L).toArray
		val idMap = new Array[Long](line.size)
		line.groupBy(_._1).foreach { case (pgr, ylist) =>
			ylist.toSeq.map(_._2).sortBy(_._1).map(_._2).zipWithIndex.foreach { case (gi, yindex) =>
				//val id = "%06d%06d".format(pgr, (yindex + 1))
				//val id = str(pgr, yindex)
				////println(gi, id)
				////idMap = idMap + (gi -> id)
				//idMap(gi) = id

				idMap(gi) = 1000000L * pgr + (yindex + 1)
			}
		}
		val pw = new java.io.PrintWriter(System.out)
		idMap.foreach { e =>
			val tmp = java.lang.Long.toString(1000000000000L + e).substring(1, 13)
			pw.println(tmp)
		}
		pw.flush()
	}

//	private val start = System.currentTimeMillis()
//	func((0 until 100).map(i => (i % 2) + " " + i).toIterator)
//	//func((0 until 100).map(i => (i % 1) + " " + -i))
//	func((0 until 100000).map(i => (i % 2) + " " + i).toIterator)
//	//func((0 until 100000).map(i => (i % 1) + " " + -i))
//	func((0 until 100000).map(i => i + " " + i).toIterator)
//	println(System.currentTimeMillis() - start)

	//TODO 入力が遅い？
	private val lines: Iterator[String] = scala.io.Source.stdin.getLines
	lines.next()
	func(lines)
}
