{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import qualified Data.Text as T 
import qualified Data.Vector as V
import Data.List
f :: [Int]->Int->T.Text->V.Vector Int
f n k l=if T.length (T.tail l) == 0 then V.fromList n else if (T.head l)=='A'&&((T.head).(T.tail)) l=='C' then f (n++[k+1]) (k+1) (T.tail l) else f (n++[k]) k (T.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<-getLine
 l<-Prelude.map (Prelude.map read.words)<$>replicateM q Prelude.getLine ::IO[[Int]]
 putStr$unlines$Prelude.map show$Prelude.map (g (f [0] 0 (T.pack s))) l