import Data.List
import Control.Monad
main = do
    [n, q] <- fmap read . words <$> getLine :: IO [Int]
    s <- getLine

    let ac = scanl (+) 0 $ (\x -> if x == "AC" then 1 else 0) . take 2 <$> tails s
    forM_ [1..q] . const $ do
        [l, r] <- fmap pred . fmap read . words <$> getLine
        print $ (ac !! r) - (ac !! l)
