import java.util.Scanner

import scala.annotation.tailrec
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)(Vector.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, city._2 +: map(city._1 - 1))
  }
  (0 until N).foreach { i => map.update(i, map(i).sorted) }

  seq.foreach { city =>
    val ys = map(city._1 - 1)
    val rank = find(ys, city._2, 0, ys.size - 1) + 1
    println("%06d%06d".format(city._1, rank))
  }

  @tailrec def find(xs: Vector[Int], value: Int, min: Int, max: Int): Int = {
    val idx = (max + min) / 2
    val v = xs(idx)
    if (v == value) {
      idx
    } else if (v < value) {
      find(xs, value, idx + 1, max)
    } else {
      find(xs, value, min, idx - 1)
    }
  }
}
