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(_ =>
      readLine.split(" ").map(_.toInt) match {
        case Array(p, y) => (p, y)
      })

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

  def convert(p: Int, order: Int) = f"${p}%06d${order}%06d"
  val pw = new java.io.PrintWriter(System.out)
  lines.map { case (p, y) => convert(p, map(p)(y)) }.foreach{ res =>
    pw.println(res)
  }
  pw.flush
}