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