n, q = gets.chomp.split.map(&:to_i)
queue = Array.new

n.times do |i|

   input = gets.chomp.split
   name = input[0]
   time = input[1].to_i
   queue.push [name, time]

end

flag = true
time = 0
while flag

   diff = queue[0][1] - q
   name = queue[0][0]

   if diff > 0

      queue.shift
      queue.push [name, diff]
      time += q

   else

      time += queue[0][1]
      puts "#{name} #{time}"
      queue.shift

   end

   flag = false if queue[0].nil?
   break if flag == false

end