import Control.Monad
import qualified Data.Sequence as C

main :: IO ()
main = do
  [n, q] <- readInts
  s <- C.fromList <$> getLine
  let sol = solve s
  lrs <- replicateM q readInts
  forM_ lrs $ \[l, r] -> do
    print $ (sol `C.index` r) - (sol `C.index` l)

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: C.Seq Char -> C.Seq Int
solve s = (0 C.<|)
  $ C.scanl (+) 0
  $ fmap (\x -> if x == ('A', 'C') then 1 else 0)
  $ C.zip s (C.drop 1 s C.|> '_')