### subroutines

def parse_name(name)
  return name.split('_') if ! name.index('_').nil?

  name[0] = name[0].upcase
  name.scan(/[A-Z][a-z]*/).map{|s| s.downcase}
end

### main

loop do
  name, type = gets.strip.split
  break if type == 'X'
  #p [name, type]

  words = parse_name(name)

  case type
  when 'U'
    puts words.map{|s| s[0] = s[0].upcase; s}.join('')
  when 'L'
    cc = words.map{|s| s[0] = s[0].upcase; s}.join('')
    cc[0] = cc[0].downcase
    puts cc
  when 'D'
    puts words.join('_')
  end
end