class dice init = object (self)
  val mutable d:int*int*int*int*int*int = init

  method private tn (x1,x2,x3,x4,x5,x6):int*int*int*int*int*int = (x2,x6,x3,x4,x1,x5)
  method private ts l = self#tn l |> self#tn |> self#tn
  method private te (x1,x2,x3,x4,x5,x6):int*int*int*int*int*int = (x4,x2,x1,x6,x5,x3)
  method private tw l = self#te l |> self#te |> self#te

  method id = ()
  method north = d <- self#tn d
  method south = d <- self#ts d
  method east = d <- self#te d
  method west = d <- self#tw d
  method top = match d with (x1,_,_,_,_,_) -> x1
end;;

let split_int s = Str.split (Str.regexp_string " ") s |> List.map int_of_string;;
let n = read_line () |> split_int |> List.nth and
    s = read_line () in
    let l = (n 0,n 1,n 2,n 3,n 4,n 5) in
    let d = new dice l in
    let rec loop = function
        i when i = String.length s -> Printf.printf "%d\n" d#top
      | i -> ( match s.[i] with
               'N' -> d#north
             | 'S' -> d#south
             | 'E' -> d#east
             | 'W' -> d#west
             | _ -> d#id );
             loop (i+1)
    in loop 0;;