import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.List

main :: IO ()
main = do
    [n,q] <- map read . words <$> getLine :: IO [Int]
    s <- getLine :: IO String
    lr <- map ((\[a,b] -> (a,b)) . map (fst . fromJust . BS.readInt) . BS.words) . BS.lines <$> BS.getContents
    mapM_ (print . solve s) lr

part :: Int -> Int -> [a] -> [a]
part i n = take n . drop i

countPartOf :: Eq a => [a] -> [a] -> Int
countPartOf _ [] = 0
countPartOf [] _ = 0
countPartOf a b = if a `isPrefixOf` b
                  then succ $ countPartOf a (drop (length a) b)
                  else countPartOf a (drop 1 b)

solve :: String -> (Int,Int) -> Int
solve s (l,r) =  countPartOf "AC" (part (l-1) (r-l+1) s)
