dice = gets.split.map(&:to_i)
commands = gets.chomp.chars.map(&:to_sym)
throw = {E: [3, 2, 6, 1, 5, 4], N: [5, 1, 3, 4, 6, 2],
         S: [2, 6, 3, 4, 1, 5], W: [4, 2, 1, 6, 5, 3]}
th = {}
throw.each_key {|k| th[k] = throw[k].map(&:pred)}

commands.each do |c|
  next_dice = Array.new(6, 0)
  dice.each_with_index do |d, i|
    next_dice[th[c][i]] = d
  end
  dice = next_dice
end
puts dice[0]

