import collection.mutable.Queue
import java.util._
 
object Main {
  val sc = new Scanner(System.in)
  val map = new HashMap[String,Int]
  val q = Queue[String]()
  val n = sc.nextInt
  val proces = sc.nextInt
  
  
  
  
  def main(args: Array[String]): Unit = {
    for( i <- 0 until n){
      var temp = sc.next
      q.enqueue(temp)
      map.put(temp, sc.nextInt)
    }
    new Solve().main
  }
  
  
  
  
  class Solve{
      def main{
        var count = 0
        while(!q.isEmpty){
          var temp = q.dequeue() 
          
          if(map.get(temp) - proces > 0){
            map.put(temp ,map.get(temp) - proces)
            q.enqueue(temp)
            count += proces
          }else {
            count += map.get(temp)
            println(temp + " " +  count)
          }
              
        }
    }
  }
}