command_table = {
  "N" => 0,
  "S" => 1,
  "W" => 2,
  "E" => 3
}

table = {
  1 => [2,5,3,4],
  2 => [6,1,3,4],
  3 => [2,5,6,1],
  4 => [2,5,1,6],
  5 => [1,6,3,4],
  6 => [5,2,3,4]
}

dice = gets.split
puts dice[gets.chomp.chars.map {|x| command_table[x] }.reduce {|acc, x| table[acc][x] } - 1]