class Dice
  attr_reader :current
  def initialize(@current = 1, @north = 5, @east = 3)
  end

  def roll(direction)
    case direction
    when "N"
      @current, @north = 7 - @north, @current
    when "S"
      @current, @north = @north, 7 - @current
    when "E"
      @current, @east  = 7 - @east, @current
    when "W"
      @current, @east  = @east, 7 - @current
    end
    Dice.new(@current, @north, @east)
  end
end

dice = gets.split
puts dice[gets.chomp.chars.reduce(Dice.new) {|acc, x| acc.roll(x) }.current - 1]