n,q = gets.chomp.split.map(&:to_i)
queue = []
n.times {
  arr = gets.chomp.split
  queue << [arr[0],arr[1].to_i]
}
time = 0
while queue.length > 0
  arr = queue.shift
  if arr[1] <= q
    time += arr[1]
    puts "#{arr[0]} #{time}"
  else
    time += q
    queue << [arr[0],arr[1]-q]
  end
end