object Main extends App {
  val (n, m) = readLine.split(" ").map(_.toInt) match {
    case Array(n, m) => (n, m)
  }

  val lines: Seq[(Int, Int)] = (1 to m)
    .map(i =>
      readLine.split(" ").map(_.toInt) match {
        case Array(p, y) => (p, y)
    })

  def convert(p: Int, order: Int) = f"${p}%06d${order}%06d"

  val map: Map[(Int, Int), String] =
    lines
      .groupBy(_._1)
      .flatMap { case (p, s) =>
        s.sortBy(_._2).toStream.zipWithIndex.map {
          case ((p, y), index) => ((p, y), convert(p, index + 1))
        }
      }


  lines.foreach { case (p, y) => println(map((p, y))) }

}