k = [:t,:f,:l,:r,:b,:d]
dc = Hash[*k.zip(gets.split(" ").map(&:to_i)).flatten]
gets.split("").each do |a|
  case a
  when "N"
    dc.merge!({t:dc[:f],f:dc[:d],b:dc[:t],d:dc[:b]})
  when "E"
    dc.merge!({t:dc[:r],l:dc[:t],r:dc[:d],d:dc[:l]})
  when "W"
    dc.merge!({t:dc[:l],l:dc[:d],r:dc[:t],d:dc[:r]})
  when "S"
    dc.merge!({t:dc[:b],f:dc[:t],b:dc[:d],d:dc[:f]})
  end
end
puts dc[:t]