import Control.Monad
f n k (s:l)=if null l then n else if s=='A'&&(head l)=='C' then if null (tail l) then n++[k] else f (n++[k]) (k+2) (tail l) else f n (k+1) l 
g s l = length [x|x<-s,(l!!0)<=x,x<(l!!1)]
main=do
 [n,q]<-map read.words<$>getLine
 s<-getLine
 l<-map (map read.words)<$>replicateM q getLine
 putStr$unlines$map show$map (g (f [] 1 ((drop ((minimum.map head)l-1).take((maximum.map last)l-1))s))) l