import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Char (toUpper, toLower)
import Text.Parsec
import Text.Parsec.String

main :: IO ()
main = do
  [n,t] <- words <$> getLine
  unless (t == "X") $ do
    putStrLn $ solve n t
    main

solve :: String -> String -> String
solve n t
  | t == "U" = concatMap up xs
  | t == "L" = lo (head xs) ++ concatMap up (tail xs)
  | otherwise = intercalate "_" $ map lo xs
  where
    xs = either (const [""]) id $ parse anl "" n

sc :: Parser [String]
sc = sepBy1 (many1 (lower <|> digit)) (char '_')

uc :: Parser [String]
uc = many1 ((:) <$> upper <*> many1 (lower <|> digit))

lc :: Parser [String]
lc = (:) <$> many1 (lower <|> digit) <*> uc

anl :: Parser [String]
anl = uc <|> try lc <|> sc

up :: String -> String
up xs = (toUpper $ head xs) : tail xs

lo :: String -> String
lo xs = (toLower $ head xs) : tail xs

