import java.util.Scanner

import scala.collection.mutable

object Main extends App {
  val sc = new Scanner(System.in)
  val N, M = sc.nextInt
  val ordering = Ordering.fromLessThan[City](_.y < _.y)
  val map = Array.fill(N)(mutable.TreeSet.empty(ordering))
  val seq = mutable.ListBuffer.empty[City]
  (0 until M).foreach { _ =>
    val city = City(sc.nextInt, sc.nextInt)
    seq.append(city)
    map.update(city.p - 1, map(city.p - 1) + city)
  }
  seq.foreach { city =>
    val rank = map(city.p - 1).zipWithIndex.find(z => z._1 == city).get._2 + 1
    println("%06d".format(city.p) + "%06d".format(rank))
  }
}

case class City(p: Int, y: Int)
