import scala.io.{StdIn => in}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)

  case class Id(i: Int, p: Int, x: Int)

  val city = Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" "))
    .zipWithIndex
    .map(a => new Id(a._2.toInt, a._1(0).toInt, a._1(1).toInt))
    .toArray

  val sortedCity = city
    .sorted {
      new Ordering[Id] {
        def compare(x: Id, y: Id): Int = (
          x.p.compareTo(y.p) match {
            case 0 => x.x.compareTo(y.x)
            case c => c
          })
      }
    }
    .scanLeft((0, 0, 0)) { (acc, city) =>
        if(acc._2 == city.p) (city.i, acc._2, acc._3 + 1)
        else (city.i, city.p, 1)
      }
    .tail
    .sortBy(_._1)

  sortedCity.foreach { id =>
        val p = Array.fill(6 - rec(0, id._2))('0').mkString
        val x = Array.fill(6 - rec(0, id._3))('0').mkString
        out.println(p + id._2 + x + id._3)
      }
  out.flush

  def rec(cnt:Int, v: Int):Int = {
    if(v == 0) cnt
    else rec(cnt+1, v / 10)
  }
}