n, q= gets.split(" ").map { |x| x.chomp.to_i }

queue =  n.times.map{ gets.chomp.split(" ") }.map{ |k ,v| [k, v.to_i]}

time = 0
until queue.empty?
  s = queue.shift
  if s[1] <= q
    time += s[1]
    printf "%s %s\n", s[0], time
  else
    time += q
    s[1] -= q
    queue << s
  end
end
