while (ary = gets.split) != ["EndOfInput", "X"]
  str_ary = []
  tmp_str = ary[0][0]
  for num in (1..(ary[0].size - 1))
    tmp_char = ary[0][num]
    unless tmp_char == "_" or tmp_char.ord.between?(65, 90)
      tmp_str += tmp_char
      next
    else
      str_ary << tmp_str
      if tmp_char == "_"
        tmp_str = ""
      else
        tmp_str = tmp_char
      end
    end
  end
  str_ary << tmp_str

  case ary[1]
  when "L"
    for num in (1..(str_ary.size - 1))
      str_ary[num].capitalize!
    end
    puts str_ary.join
  when "U"
    str_ary.each {|s| s.capitalize!}
    puts str_ary.join
  when "D"
    str_ary.each {|s| s.downcase!}
    puts str_ary.join("_")
  end
end