import Control.Monad
import Data.List
import Data.Vector.Unboxed (Vector,(!))
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as B

main = do
  [_,q] <- readIntsLn
  s <- getLine
  let c = solve s
  qs <- replicateM q readIntsLn
  forM_ qs $ \[l,r] -> print (c!r - c!l)
  
solve :: String -> Vector Int
solve = U.fromList . f 0 where
  f a [] = [a]
  f a ('A':'C':s) = a : a : f (a+1) s
  f a (c:s) = a : f a s

readIntsLn
  = unfoldr (B.readInt . B.dropWhile(==' ')) <$> B.getLine