type dice = {
  one : int ;
  two : int ;
  three : int ;
  four : int ;
  five : int ;
  six : int };;

let throw_dice dir dice  =
  match dir with
    "W" -> {dice with one = dice.three;
                      three = dice.six;
                      six = dice.four;
                      four = dice.one}
  | "E" -> {dice with one = dice.four;
                      four = dice.six;
                      six = dice.three;
                      three = dice.one}
  | "S" -> {dice with one = dice.five;
                      two = dice.one;
                      six = dice.two;
                      five = dice.six}
  | _ -> {dice with one = dice.two;
                      two = dice.six;
                      six = dice.five;
                      five = dice.one};;

let check_dicenum str dice =
  let len = String.length str in
  let rec f i d =
    if i = len then d.one
    else f (i+1) (throw_dice (Char.escaped str.[i]) d)
  in
  f 0 dice ;;

let () =
  let as_ = Array.init 6 (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let dice = {one = as_.(0); two = as_.(1); three = as_.(2); four = as_.(3); five = as_.(4); six = as_.(5)} in
  let str = Scanf.scanf "%s\n" (fun a -> a) in
  Printf.printf "%d\n" (check_dicenum str dice) ;;
