process_list = []
STDIN.each_line {|line|
  res = line.split " "
  process_list.push res
}

result_time = 0
a = process_list.shift
process_count = a[0].to_i
quantum_time = a[1].to_i
while process_list.length != 0
  process = process_list.shift
  consume_time = process[1].to_i
  if consume_time <= quantum_time
    result_time = result_time + consume_time
    print process[0], " ", result_time, "\n"
    next
  end

  result_time = result_time + quantum_time
  process[1] = (consume_time - quantum_time).to_s
  process_list.push process
end
