permutations = {
  ?E => [2, 1, 5, 0, 4, 3],
  ?N => [4, 0, 2, 3, 5, 1],
  ?S => [1, 5, 2, 3, 0, 4],
  ?W => [3, 1, 0, 5, 4, 2],
}
dice = gets.split.map(&:to_i)
gets.chomp.each_char do |d|
  p = permutations[d]
  dice = dice.each_with_index.sort_by {|_, i| p[i] }.map(&:first)
end
p dice[0]