MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '5 100
  p1 150
  p2 80
  p3 200
  p4 350
  p5 20'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

n, q = line[0].split.map(&:to_i)
process = []
(1..n).each do |num|
  p, t = line[num].split
  t = t.to_i
  process.push [p, t]
end
 
total = 0
while process.any?
  p, t = process.shift
  if t <= q
    total += t
    puts "#{p} #{total}"
  else
    t -= q
    total += q
    process.push [p, t]
  end
end