object Main extends App {
  val line = io.Source.stdin.getLines.toIndexedSeq.tail
  .map{ e=>
    val tmp = e.split(' ').map(_.toInt).toArray
    (tmp(0), tmp(1))
  }.zipWithIndex
  val groupByP = line.sortBy(_._1._2).groupBy(_._1._1)
  .map{ case (pgr,ylist) =>
   	ylist.zipWithIndex.map{ case (yi, yindex) =>
      val gi = yi._2
      val id = "%06d%06d".format(pgr, (yindex+1))
      //println(gi, id)
      (gi, id)
    }
  }
  val ret = groupByP.flatten.toSeq.sortBy(_._1)
  ret.foreach(e => println(e._2))
}