class Dice
 
 attr_reader :upper_number
 def initialize(numbers)
  @numbers = numbers.unshift 0
  @upper_number = numbers[0]
 end
 def rotate(instruction)
  instruction.split('').each{|op|
   when op
   case 'W'
    tmp = @numbers[1]
    @numbers[1]=@numbers[3]; @numbers[3]=@numbers[6]; @numbers[6]=@numbers[4]; @numbers[4]=tmp

   case 'E'
    tmp = @numbers[1]
    @numbers[1]=@numbers[4]; @numbers[4]=@numbers[6]; @numbers[6]=@numbers[3]; @numbers[3]=tmp

   case 'S'
    tmp = @numbers[2]
    @numbers[2]=@numbers[1]; @numbers[1]=@numbers[5]; @numbers[5]=@numbers[6]; @numbers[6]=tmp
   case 'N'
    tmp = @numbers[2]
    @numbers[2]=@numbers[6]; @numbers[6]=@numbers[5]; @numbers[5]=@numbers[1]; @numbers[1]=tmp
  }
  @upper_number = numbers[0]
 end
end

numbers = gets.split.collect{|i|i.to_i}
instruction = gets
dice = Dice.new numbers
dice.rotate instruction
puts dice.upper_number