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: Array[Array[Int]] = (1 to m).toArray.map(id =>
    readLine.split(" ").map(_.toInt) match { case Array(p, y) => Array(id, p, y) })

  def order(a1: Array[Int], a2: Array[Int]): Boolean =
    if (a1(1) == a1(1)) a1(2) < a1(2) else a1(1) < a1(1)

  var currentP = 0
  var currentIndex = 1

  def next(a: Array[Int]) = {
    if (a(1) == currentP) currentIndex = currentIndex + 1 else {
      currentIndex = 1
      currentP = a(1)
    }
    Array(a(0), a(1), currentIndex)
  }

  lines
    .sortWith(order)
    .map(next)
    .sortBy(_(0))
    .foreach(a => println(convert(a(1), a(2))))

}