inputs = gets.to_s.split(" ")

process_number = inputs[0].to_i
q_time = inputs[1].to_i
process_time = 0
i = 0
process = []
process_finish = []
for j in 0..process_number-1 do 
  process[j] = gets.to_s.split(" ")
end

while process.length != 0
  process_start = process[0][1].to_i - q_time

  if process_start > 0
    process[0][1] = process_start
    process.push(process[0])
    process.shift
    process_time += q_time
  end

  if process_start < 0
    process_time += (process[0][1].to_i)
    process[0][1] = process_time
    process_finish << process[0]
    process.shift
  end

  if process_start == 0
    process_time += q_time
    process[0][1] = process_time
    process_finish << process[0]
    process.shift
  end
end

for k in 0..process_number-1 do 
  puts process_finish[k].join(" ").strip
end

