import java.util.Scanner

import scala.collection.mutable

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