{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> String -> Int -> [Int] -> [Int]
solve n s q ks = map count ks
  where

  appD = mkCntVec 'D' s
  appC = mkCntVec 'C' s

  count k = sum $ unfoldr (cntNxt k) (0, -1, (zip [0..] s))

  cntNxt k (thisCnt, mPre, i_s)
    | null i_sB = Nothing
    | otherwise = Just (newCnt, (newCnt, jm, i_sB2))
    where
    (i_sA, i_sB) = break ((== 'M') . snd) i_s
    (jm,'M') : i_sB2 = i_sB
    newCnt = thisCnt + (inc - dec)
    inc = sum $ map f [i | (i,c) <- i_sA, c == 'D']
      where f i | i+k <= jm = 0
                | otherwise = (appC VU.! (min (i+k-1) (n-1)))
                              - (appC VU.! jm)
    dec = sum $ map f [i | (i,c) <- i_sA, c == 'C']
      where f i | mPre < 0      = 0
                | mPre <= i-k+1 = 0
                | i-k < 0       =  appD VU.! mPre
                | otherwise     = (appD VU.! mPre) - (appD VU.! (i-k))

mkCntVec c0 s = VU.fromList lst
  where (_, lst) = mapAccumL (ccount c0) 0 s

ccount c0 cnt c | c == c0   = (cnt + 1, cnt + 1)
                | otherwise = (cnt,     cnt)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> [Int]
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      [bs_s]:remLines2 = remLines1
      s = B.unpack bs_s
      [bs_q]:remLines3 = remLines2
      q = readBInt bs_q
      line4:remLines4 = remLines3
      ks = map readBInt line4
  in solve n s q ks

outAnswer :: [Int] -> IO ()
outAnswer xs = putStr $ unlines $ map show xs

main :: IO ()
main = outAnswer . tmain =<< B.getContents
