main :: IO()
main = getContents >>= putOut.show.solve.formatIn
  where putOut s | null s || last s == '\n' = putStr s
                 | otherwise                = putStrLn s
   
formatIn :: String -> ([Int], String)
formatIn = (\(x:y:_) -> (map read $words x, y)).lines

solve :: ([Int], String) -> Int
solve (xs,ys) = head $foldl label xs ys 

label (x1:x2:x3:x4:x5:x6:_) c
    | c == 'E' =  [x4,x2,x1,x6,x5,x3]
    | c == 'N' =  [x2,x6,x3,x4,x1,x5]
    | c == 'S' =  [x5,x1,x3,x4,x6,x2]
    | c == 'W' =  [x3,x2,x6,x1,x5,x4]