import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V

main :: IO ()
main = readLine >>= main'
    where
        main' nq = getLine >>= main'' nq
        main'' [n, q] s = readContents q >>= printRes . solve n s
        printRes = mapM_ print 

solve :: Int -> String -> [[Int]] -> [Int]
solve n s = map answer
    where
        vs = V.fromList $ 0 : build 0 s

        build acc (x : y : zs)
            | x == 'A' && y == 'C' = acc : (acc + 1) : build (acc + 1) zs
            | otherwise = acc : build acc (y : zs)
        build _ [] = []
        build acc _ = [acc]

        answer [l, r] = vs V.! r - vs V.! l


readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine