class Dice
  def initialize(lbl)
    @lbl = lbl
  end

  def W
    Dice.new(*[2,1,5,0,4,3].map{|x| @lbl[x]})
  end
  def E
    Dice.new(*[3,1,0,5,4,2].map{|x| @lbl[x]})
  end
  def N
    Dice.new(*[1,5,2,3,0,4].map{|x| @lbl[x]})
  end
  def S
    Dice.new(*[4,0,2,3,5,1].map{|x| @lbl[x]})
  end

  [:top, :front, :right, :left, :back, :bottom].each_with_index do |x,i|
    define_method(x){ @lbl[i] }
  end
end

dice = Dice.new(*gets.split)
gets.chars do |c|
  eval "dice.#{c}"
end

puts dice.top