import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
main=putStr.f.g.B.lines=<<B.getContents
ris=map(fst.fromJust.B.readInt).B.words
g(nq:s:lrs)=(ris nq,s,map ris lrs)
f([n,q],s,lrs)=unlines$map(\[l,r]->show$vs V.!r - vs V.!l)lrs where
  vs=V.fromList$scanl'(+)0$0:B.zipWith(\x y->if x=='A' && y=='C' then 1 else 0)s(B.tail s)