while l = gets
  name, type = l.split
  break if type == "X"
  ret = ""
  if name.include?("_") 
    names = name.split("_")
    sz = names.size
    if type == "L"
      ret = names[0]
    elsif type == "U"
      ret = names[0].capitalize
    end
    (1..sz-1).each do |i|
      ret << names[i].capitalize
    end
  else
    sz = name.size
    if type == "U"
      x = name[0].capitalize
      ret << x << name[1,sz-1]
    else
      x = name[0].downcase
      ret = x
      if type == "L"
        ret << name[1,sz-1]
      else
        (1..sz-1).each do |i|
          if name[i].match(/[A-Z]/) == nil
            ret << name[i]
          else 
            ret << "_" << name[i].downcase
          end
        end
      end
    end
  end
  puts ret 
end