object Main extends App {
  val lines = io.Source.stdin.getLines.toIndexedSeq
  //val N = lines.head.split(' ').map(_.toInt).head
  //val accs = (0 until N).toArray.map(_=>0)
  val line = lines.tail.zipWithIndex.map{ case (e, gi) =>
    val tmp = e.split(' ').map(_.toInt).toArray
    (tmp(0), (tmp(1), gi))
  }
  val groupByP = line.groupBy(_._1).map{ case (pgr, ylist) =>
   	ylist.sortBy(_._1).zipWithIndex.map{ case (yi, yindex) =>
      val gi = yi._2._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))
}