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] = foldl (\acc x -> if (s !! x == 'A') && (s !! (x + 1) == 'C') then acc + 1 else acc) 0 [(l-1)..(r-2)]

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