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

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

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

  lines
    .groupBy { case (id, p, y) => p }
    .flatMap {
      case (p, s) =>
        s.sortBy { case (_, _, y) => y }
          .zip(Stream.from(1))
          .map {
            case ((id, p, y), index) => (id, convert(p, index))
          }
    }
    .toSeq
    .sortBy(_._1)
    .foreach(println)

}