import scala.collection.immutable.Queue
import java.util.Scanner

object Main {

  implicit class RichString(string: String) {
    def readFirstLine: (Int, Int) = {
      val t = string.split(' ')
      (t(0).toInt, t(1).toInt)
    }
    def line2Process: Process = {
      val t = string.split(' ')
      Process(t(0), t(1).toInt)
    }
  }

  case class Process(name: String, time: Int)

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val (n, cycleTime): (Int, Int) = sc.nextLine().readFirstLine
    val pList = List.fill(n)(sc.nextLine().line2Process)
    val pQueue = Queue(pList: _*)
    genRound(cycleTime)(pQueue, 0)
  }

  def genRound(cycleTime: Int): (Queue[Process], Int) => Unit =
    round(_, _)(cycleTime)

  def round(q: Queue[Process], time: Int)(implicit cycleTime: Int): Unit = {
    q.dequeueOption match {
      case None => ()
      case Some((Process(n, t), nextQueue)) if t - cycleTime <= 0 => {
        val nowTime = time + t
        println(s"$n $nowTime")
        round(nextQueue, nowTime)
      }
      case Some((Process(n, t), nextQueue)) =>
        round(nextQueue.enqueue(Process(n, t - cycleTime)), time + cycleTime)
    }
  }
}

