object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, m = sc.nextInt
    val items = new Array[(Int, Int, Int, String)](m)
    for (i <- 0 until m) {
      items(i) = (i, sc.nextInt, sc.nextInt, "")
    }

    val itemsSorted = items.sortWith(
      (v1, v2) =>
        if (v1._2 != v2._2) {
          (v1._2 < v2._2)
        } else {
          (v1._3 < v2._3)
        }
    )
    var currentP = -1
    var index = 1
    for (i <- 0 until m) {
      if (currentP != itemsSorted(i)._2) {
        currentP = itemsSorted(i)._2
        index = 1
      }
      itemsSorted(i) = (itemsSorted(i)._1, itemsSorted(i)._2, itemsSorted(i)._3, String.format("%06d%06d", currentP, index))

      index += 1
    }

    itemsSorted.sortBy(_._1).foreach(v => println(v._4))
  }

}