object Main extends App {
	private def zeros(yid: String): String = {
		val len = yid.length
		if (len == 0) "000000"
		else if (len == 1) "00000"
		else if (len == 2) "0000"
		else if (len == 3) "000"
		else if (len == 4) "00"
		else if (len == 5) "0" else ""
	}

	private def str(pgr: Int, yindex: Int): String = {
		//val id = "%06d%06d".format(pgr, (yindex + 1))
		val yid = Integer.toString(yindex + 1)
		val prey = zeros(yid)
		val pid = Integer.toString(pgr)
		val prep = zeros(pid)
		prep + pid + prey + yid
	}

	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(_ => (-1, -1)).toArray
		line.groupBy(_._1).foreach { case (pgr, ylist) =>
			ylist.toSeq.map(_._2).sortBy(_._1).map(_._2).zipWithIndex.foreach { case (gi, yindex) =>
				//val id = str(pgr, yindex)
				////println(gi, id)
				////idMap = idMap + (gi -> id)
				//idMap(gi) = id

				idMap(gi) = (pgr, yindex)
			}
		}
		val pw = new java.io.PrintWriter(System.out)
		idMap.foreach(e => pw.println(str(e._1, e._2)))
		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 % 1) + " " + -i))
//	func((0 until 100000).map(i => -i + " " + -i))
//	println(System.currentTimeMillis() - start)

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