m "North" [a,b,c,d,e,f] = [f,b,e,d,a,c]
m "East"  [a,b,c,d,e,f] = [d,a,b,c,e,f]
m "West"  [a,b,c,d,e,f] = [b,c,d,a,e,f]
m "South" [a,b,c,d,e,f] = [e,b,f,d,c,a]
m "Right" [a,b,c,d,e,f] = [a,e,c,f,d,b]
m "Left"  [a,b,c,d,e,f] = [a,f,c,e,b,d]
m _ d = d

ans' s _ [] = s
ans' s d (c:cs) =
  let d' = m c d
      s' = d'!!0
  in
    ans' (s+s') d' cs

ans [] = []
ans ("0":_) = []
ans ("":_) = []
ans (n:x) =
  let n' = read n :: Int
      d  = take n' x
      r  = drop n' x
  in
    (ans' 1 [1,3,6,4,5,2] d):(ans r)

main = do
  c <- getContents
  let i = lines c
      o = ans i
  mapM_ print o