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