loop {
    s, type = gets.chomp.split
    break if type == ?X
    a = s.split(/_|(?=[A-Z])/).map(&:downcase)
    case type
    when ?L
        puts a[0] + a[1..a.size-1].map(&:capitalize).join
    when ?U
        puts a.map(&:capitalize).join
    when ?D
        puts a.join("_")
    end 
}