def main inputs
  inputs = inputs.dup
  size, quantum = inputs.shift.split(' ').map{|n|n.to_i}
  time = 0
  done = []
  until inputs.empty?
    target_name, target_rest = inputs.shift.split ' '
    # target 180, quantum 100?????¨???
    # ??????????????£??????????????? 100
    # ???????????? 80
    #
    # target 80, quantum 100?????¨???
    # ??????????????£??????????????? 80
    # ???????????? 0
    #
    # ????????????
    rest = target_rest.to_i - quantum
    # ????????????????????´???
    if rest <= 0
      time = time + target_rest.to_i
      done.push("#{target_name} #{time}")
    else
      # ??????????????????????????´???
      time = time + quantum
      # ????????´???
      inputs.push "#{target_name} #{rest}"
    end
  end
  done.join "\n"
end


inputs = STDIN.read.split(/\n/)

puts main(inputs)