def main
  n, q, jobs = input

  ans = []
  time = 0
  while not jobs.empty?
    job = jobs.first

    if job[:time] <= q
      time += job[:time]
      ans << { :name => job[:name], :time => time}
      jobs.delete_at(0)
    else
      time += q
      newjob = { :name => job[:name], :time => job[:time] - q}
      jobs.delete_at(0)
      jobs << newjob
    end
  end
  ans.each do |info|
    puts "#{info[:name]} #{info[:time]}"
  end
end

def input
  n, q = gets.chomp.split(/\s/).collect { |x| x.to_i}
  jobs = []
  (1..n).each do |i|
    str = gets.chomp.split(/\s/)
    pname, time = str[0], str[1].to_i
    jobs << { :name => pname, :time => time}
  end
  [n, q, jobs]
end

main