n, q = gets.split.map(&:to_i)

queue = Array.new(n).map do
  a = gets.split
  [a[0], a[1].to_i]
end

ans = []
time = 0

while !queue.empty?
  tmp = queue.shift
  tmp[1] -= q
  if tmp[1] > 0
    time += q
    queue.push(tmp)
  else
    time += q + tmp[1]
    ans.push([tmp[0],time])
  end
end

puts ans.map{|a| a.join(" ")}
