class Array
  def round_robin_scheduling(q)
    time = 0
    while !empty? do
      time += [first[1].to_i, q].min
      first[1] = first[1].to_i - [first[1].to_i, q].min
      first[1] == 0 ? (puts [shift[0], time].join(" ")) : (self << shift)
    end
  end
end

n, q = gets.split.map(&:to_i)
schedules = []
n.times do
  schedules << gets.split
end
schedules.round_robin_scheduling(q)

