{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import Data.List
f :: [Int]->Int->B.ByteString->V.Vector Int
f n k l=if B.null(B.tail l) then V.fromList n else if (B.head l)=='A'&&((B.head).(B.tail)) l=='C' then f ((k+1):n) (k+1) (B.tail l) else f (k:n) k (B.tail l)
g n l = (n V.! ((l!!1)-1)) - (n V.!((l!!0)-1))
main=do
 [n,q]<-Prelude.map read.words<$>Prelude.getLine ::IO[Int]
 s<-B.getLine
 l<-Prelude.map (Prelude.map read.words)<$>replicateM q Prelude.getLine ::IO[[Int]]
 putStr$unlines$Prelude.map show$Prelude.map ((g.reverse) (f [0] 0 (s))) l
