import Control.Monad (replicateM)
import Data.List

main :: IO ()
main = do
  [n,q] <- map (read :: String -> Int) . words <$> getLine
  s <- getLine
  lrs <- map (map (read :: String -> Int)) . map words <$> getNLine_ q
  mapM_ print $ map (ans s) lrs

ans :: String -> [Int] -> Int
ans s [l,r] = length . filter (\x -> l-1 <= x && x <= r-2) $ myIndex s

myIndex :: String -> [Int]
myIndex s = findIndices (isPrefixOf "AC") (tails s)

getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine