object Main extends App {
	private def func(lines: Seq[String]) {
		val line = lines.tail.zipWithIndex.map { case (e, gi) =>
			val tmp = e.split(' ').map(_.toInt).toArray
			(tmp(0), (tmp(1), gi))
		}
		val idMap = line.indices.map(_ => "").toArray
		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 yid = Integer.toString(yindex + 1)
				val prey = (0 to 6 - yid.length).foldLeft("")((a, _) => a + "0")
				val pid = Integer.toString(pgr)
				val prep = (0 to 6 - pid.length).foldLeft("")((a, _) => a + "0")
				val id = prep + pid + prey + yid

				//println(gi, id)
				//idMap = idMap + (gi -> id)
				idMap(gi) = id
			}
		}
		val pw = new java.io.PrintWriter(System.out)
		idMap.foreach(pw.println(_))
		pw.flush()
	}

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

	func(scala.io.Source.stdin.getLines.toSeq)
}
