import Control.Monad
import Data.Array
import qualified Data.ByteString.Char8 as BS
main=do
 [n,q]<-map read.words<$>getLine
 s<-getLine
 lr<-replicateM q (map(read.BS.unpack).BS.words<$>BS.getLine)
 mapM_ print (f q lr (array(0,n)((0,0):(zip[1..n](g n s 0)))))
  where g 1 _ i = [i]
        g n ('A':'C':s) i = (i+1):(g(n-1)('C':s)(i+1))
        g n (a:s) i = i:(g(n-1)s i)
        f 0 _ _ = []
        f q ([l,r]:lr) ac = (ac!(r-1)-ac!(l-1)):(f(q-1)lr ac)