import Control.Applicative

data Dice = Dice {
	top :: Integer,
	right :: Integer,
	left :: Integer,
	front :: Integer,
	back :: Integer,
	bottom :: Integer
}

data Direction = E | N | S | W deriving (Eq, Show, Read)

main = do 
	[_top, _front, _right, _left, _back, _bottom] <- toIntList <$> getLine
	commands <- map (\x -> read [x] :: Direction) <$> getLine
	let dice = Dice { top=_top, front=_front, right=_right, left=_left, back=_back, bottom=_bottom }
	print . top $ foldl rotate dice commands


toIntList :: String -> [Integer]
toIntList = map read . words


rotate :: Dice -> Direction -> Dice
rotate d E = Dice{ 
					right = top d,
					top = left d,
					left = bottom d, 
					bottom = right d,
					front = front d,
					back = back d
}
rotate d W = Dice{ 
					left = top d, 
					top = right d,
					right = bottom d,
					bottom = left d,
					front = front d,
					back = back d
}
rotate d N = Dice{ 
					back = top d,
					top = front d,
					front = bottom d,
					bottom = back d,
					right = right d,
					left = left d
}
rotate d S = Dice{ 
					front = top d,
					top = back d,
					back = bottom d, 
					bottom = front d,
					right = right d,
					left = left d
}
