object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val n, q = sc.nextInt
    val ps = scala.collection.mutable.Queue.fill(n)((sc.next, sc.nextInt))

    var t = 0
    while(ps.nonEmpty) {
      val (name, time) = ps.dequeue()
      if(time <= q) {
        println(s"${name} ${t + time}")
        t += time
      } else {
        ps.enqueue((name, time - q))
        t += q
      }
    }
  }
}

