import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

main = do
  [n, q] <- map (read::String -> Int) . words <$> getLine
  s <- getLine
  let counts = listArray (1, n) . tail . map fst $ scanl (\(count, prv) crt -> if prv == 'A' && crt == 'C' then (count + 1, crt) else (count, crt)) (0, 'N') s
  forM [1..q] (\i -> do
    [l, r] <- map (read::String -> Int) . words <$> getLine
    print $ counts ! r - counts ! l)