data Die = Die { numb :: [Int] } deriving (Show)
roll :: Die -> Char -> Die
roll die 'E' = Die [(numb die) !! 3, 
                     (numb die) !! 1,
                     (numb die) !! 0,
                     (numb die) !! 5,
                     (numb die) !! 4,
                     (numb die) !! 2]
roll die 'N' = Die [(numb die) !! 1, 
                     (numb die) !! 5,
                     (numb die) !! 2,
                     (numb die) !! 3,
                     (numb die) !! 0,
                     (numb die) !! 4]
roll die 'S' = Die [(numb die) !! 4, 
                     (numb die) !! 0,
                     (numb die) !! 2,
                     (numb die) !! 3,
                     (numb die) !! 5,
                     (numb die) !! 1]
roll die 'W' = Die [(numb die) !! 2, 
                     (numb die) !! 1,
                     (numb die) !! 5,
                     (numb die) !! 0,
                     (numb die) !! 4,
                     (numb die) !! 3]
roll die _ = die

roll_n :: Die -> String -> Die
roll_n die [] = die
roll_n die [c] = roll die c
roll_n die (c:s) = roll_n (roll die c) s

main = do
  line <- getLine :: IO String
  let arr = map read (words line) :: [Int]
  roll_direction <- getLine
  let first_die = Die {numb = arr }
  print $ numb $ roll_n first_die roll_direction