import Data.List
type Dice = [Int]

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

solve :: [String] -> String
solve [labels,cmds] =
    let dice = [read s | s<-words labels] :: Dice in
    show . head $ foldl' rot dice cmds

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