{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [n, q] <- readInts
  s <- getLine
  inputs <- readNInts q
  foldM_ (\_ x -> print x) () $ solve s inputs

solve !s !inputs = map getAC $ map (substr s) inputs

getAC !s = getACSub 0 0 s
  where
    getACSub count _ [] = count
    getACSub count st (x:xs)
      | st == 0 && x == 'A' = getACSub count 1 xs
      | st == 1 && x == 'C' = getACSub (count + 1) 0 xs
      | otherwise = getACSub count 0 xs


substr !s ![l, r] = take (r - l + 1) $ drop (l - 1) s

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine