module Main where

import Control.Applicative

data Dice = Dice {
    top :: Int,
    south :: Int,
    east :: Int,
    west :: Int,
    north :: Int,
    bottom :: Int
}

rotateWest Dice {top=a,south=b,east=c,west=d,north=e,bottom=f} =
    Dice c b f a e d 

rotateEast Dice{top=c,south=b,east=f,west=a,north=e,bottom=d} =
    Dice a b c d e f

rotateSouth Dice{top=a,south=b,east=c,west=d,north=e,bottom=f} =
    Dice e a c d f b

rotateNorth Dice{top=e,south=a,east=c,west=d,north=f,bottom=b} =
    Dice a b c d e f

rotate dice 'W' = rotateEast dice
rotate dice 'E' = rotateEast dice
rotate dice 'S' = rotateSouth dice
rotate dice 'N' = rotateNorth dice

execRotation dice instructions =
    foldl rotate dice instructions

main = do
    (a:b:c:d:e:f:[]) <- (map read . words) <$> getLine
    instructions <- getLine
    print $ top $ execRotation (Dice a b c d e f) instructions

