n,q=gets.split.map(&:to_i)
arr=[]
n.times do |i|
  name,time=gets.split
  arr.push [name,time.to_i]
end
total=0
while !arr.empty?
  p,t=arr.shift
  if t<=q
    total+=t
    puts "#{p} #{total}"
  else
    t-=q
    total+=q
    arr.push [p,t]
  end
end