# frozen_string_literal: true

class Dice
  def initialize(params)
    @v = Array.new(6)
    (0..5).each do |i|
      @v[i] = params[i]
    end
  end

  def slide(a, b, c, d)
    tmp = @v[a]
    @v[a] = @v[b]
    @v[b] = @v[c]
    @v[c] = @v[d]
    @v[d] = tmp
  end

  def rotate_atom(char)
    case char
    when 'N'
      slide(0, 1, 5, 4)
    when 'E'
      slide(0, 3, 5, 2)
    when 'W'
      slide(0, 2, 5, 3)
    when 'S'
      slide(0, 4, 5, 1)
    end
  end

  def rotate(string)
    string.chars.each do |c|
      rotate_atom(c)
    end
  end

  def top
    @v[0]
  end
end

g = readline.split(' ')
dir = readline.chomp!
d = Dice.new(g)
d.rotate(dir)
puts d.top

