#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
=end

class Rr
  def initialize(n, qtm, vnm,vtm)
    @qtm=qtm
    @nm = Array.new(n)
    @tm = Array.new(n)
    0.upto(n-1).each{|i|
      @nm[i] = vnm[i].to_s
      @tm[i] = vtm[i].to_i
    }
  end

  def exe()
    t=0
    nm_e=[]
    tm_e=[]
    while @nm.length > 0 do
      nm=@nm.shift
      tm=@tm.shift
      if tm <= @qtm then
        t += tm
        nm_e.push(nm) 
        tm_e.push(t) 
      else
        t += @qtm
        @nm.push(nm) 
        @tm.push(tm - @qtm)
      end
    end
    0.upto(nm_e.length-1).each{|i|
      printf("%s %d\n", nm_e[i] , tm_e[i])
    }
  end

end

class Main
  def initialize()
    #fh = open("x.txt")
    fh = STDIN
    name=[]
    time=[]
    n,q = fh.gets.chomp.split.map{|x| x.to_i}
    0.upto(n-1){|i| name[i],time[i] = fh.gets.chomp.split}

    rr = Rr.new(n, q, name, time)
    rr.exe()
  end
end

if $0==__FILE__ then
  Main.new()
end