import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))

    val Array(n, m) = in.readLine().split("\\s+").map(_.toInt)
    val prefectures = Array.fill(n) {
      ArrayBuffer.empty[(Int, Int)]
    }
    for (i <- 0 until m) {
      in.readLine().split("\\s+").map(_.toInt) match {
        case Array(p, y) => prefectures(p - 1).append((y, i))
      }
    }

    val ids = Array.ofDim[(Int, Int)](m)
    for (p <- 0 until n) {
      val rankingInPrefecture = prefectures(p).sortBy(_._1)
      for (r <- rankingInPrefecture.indices) {
        ids(rankingInPrefecture(r)._2) = (p + 1, r + 1)
      }
    }

    @inline
    def print(v: Int): Unit = {
      var column = 100000
      while (true) {
        if (column > v) {
          out.print(0)
          column /= 10
        } else {
          out.print(v)
          return
        }
      }
    }

    @inline
    def println(id: (Int, Int)): Unit = {
      print(id._1)
      print(id._2)
      out.println()
    }

    for (id <- ids) {
      println(id)
    }

    out.flush()
  }
}
