loop do
  name,type = gets.split
  break if type =='X'
  if name.include?('_')
    words = name.split('_')
  else
    name.gsub!(/(.)([A-Z])/,'\1 \2')
    words = name.split
  end
  case type
  when 'U'
    puts  words.map(&:capitalize).join
  when 'L'
    words.map!(&:capitalize)
    words[0].downcase!
    puts words.join
  when 'D'
    words.map!(&:downcase)
    puts words.join('_')
  end
end