def roundRobin(q, process, time)
  currentTime = 0
  loop do
    break if process.empty?
    p = process.shift
    t = time.shift
    if t <= q
      currentTime += t
      puts p + " " + currentTime.to_s
    else
      t -= q
      process.push p
      time.push t
      currentTime += q
    end
  end
end


if __FILE__ == $0
  n, q = gets.split.map(&:to_i)
  process = []
  time = []
  n.times do
    p, t = gets.chomp.split
    process << p
    time << t.to_i
  end
  p time
  roundRobin q, process, time
  end