import Control.Applicative

type Dice = [Int]

rot :: Char -> Dice -> Dice
rot 'E' d = [d!!3, d!!1, d!!0, d!!5, d!!4, d!!2]
rot 'W' d = [d!!2, d!!1, d!!5, d!!0, d!!4, d!!3]
rot 'N' d = [d!!1, d!!5, d!!2, d!!3, d!!0, d!!4]
rot 'S' d = [d!!4, d!!0, d!!2, d!!3, d!!5, d!!1]
rot _ _ = undefined

solve :: [String] -> String
solve [labels,cmds] =
    let dice = [read s | s<-words labels] :: Dice in
    let d = foldr rot dice cmds in
    show $ d!!0

main =
    putStrLn =<< solve . take 2 . lines <$> getContents