import Data.List
main = getContents >>= putStrLn . itp1_11_a . (\[ns,os] -> (words ns, os)) . lines

itp1_11_a (ns,os) = ns !! (head (foldl' roll [1,2,3] os) - 1)
 where
  roll [x,y,z] 'E' = [(7-z),y,x]
  roll [x,y,z] 'N' = [y,(7-x),z]
  roll [x,y,z] 'S' = [(7-y),x,z]
  roll [x,y,z] 'W' = [z,y,(7-x)]