n, q = gets.chomp.split.map(&:to_i)
p_list = {}
current_time = 0

n.times do
  p, t = gets.chomp.split
  p_list[p] = t.to_i
end

while !p_list.empty?
  p_list.each_pair do |pr, time|
    p_list[pr] = time - q
    if p_list[pr] <= 0
      current_time += time
      puts pr + " " + current_time.to_s
      p_list.delete(pr)
    else
      current_time += q
    end
  end
end