n, round = gets.split(' ').map(&:to_i)
queue = (0..n-1).map { q = gets.split(' '); [q[0], q[1].to_i] }.to_h

roundtime = 0
finishes = {}

while queue.size != 0 do
  q = queue.shift
  if q[1] <= round
    roundtime += q[1]
    finishes.store(q[0], roundtime)
  else
    roundtime += round
    queue.store(q[0], q[1] - round)
  end
end

finishes.each { |k, v| puts "#{k} #{v}" }
