def split(datum)
  datum.include?('_') ? datum.split('_') : (datum.split(/([A-Z][a-z]*)/) - [""])
end

loop do
  datum, cmd = gets.split
  case cmd
  when 'L'
    head, *tail = split(datum)
    puts head.downcase + tail.map(&:capitalize).join
  when 'U'
    puts split(datum).map(&:capitalize).join
  when 'D'
    puts split(datum).map(&:downcase).join("_")
  when 'X'
    break
  end
end

