n, q = gets.chomp.split(" ").map(&:to_i)
instractions = []

n.times do
  instractions << gets.chomp.split(" ")
end

instractions_fin = []

time = 0
while true do
  a = instractions.first[1].to_i - q
  if a <= 0
    time += instractions.first[1].to_i
    instractions_fin << [instractions.first[0], time]
    instractions.shift
  else
    b = instractions.shift
    b[1] = b[1].to_i - q
    instractions << b
    time += q
  end
  if instractions.empty?
    break
  end
end

instractions_fin.each do |i|
  puts i.join(" ")
end
