class dice
	def initialize(n=Array.new(6,0))
		@num = n
		@position = { u: @num[0],
									d: @num[5],
									r: @num[2],
									l: @num[3],
									f: @num[4],
									b: @num[1]
		}
		@LRRoll = [:u, :f, :d, :b]
		@FBRoll = [:u, :r, :d, :l]
		@UDRoll = [:f, :r, :b, :l]
	end

	def value
		p @position[:u]
	end

	def move(v)
		case v
		when "N"
			Roll(@LRRoll)
		when "S"
			Roll(@LRRoll, -1)
		when "E"
			Roll(@FBRoll)
		when "W"
			Roll(@FBRoll, -1)			
		end
	end

	def Roll(Roll, v=1)
		v = -1 if v != 1
		t = @Position[Roll[0]]
		@Position[Roll[  0]] = @Position[Roll[1*v]]
		@Position[Roll[1*v]] = @Position[Roll[2*v]]
		@Position[Roll[2*v]] = @Position[Roll[3*v]]
		@Position[Roll[3*v]] = t
	end

end
n = get.chomp.split(" ").map &:to_i
d = dice.new(n)
get.chomp.chars { |c| d.move(c) }
d.value