i = gets.split.map(&:to_i)
gets.chomp.split('').each do |o|
  a, b, c, d, e, f = i
  i = case o
  when 'S' then [e, a, c, d, f, b]
  when 'E' then [d, b, a, f, e, c]
  when 'W' then [c, b, f, a, e, d]
  when 'N' then [b, f, c, d, a, e]
  end
end
p i[0]