{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Lazy.Char8 as LBS
import Control.Monad
main = do
  getLine
  s <- flip LBS.snoc ' ' . LBS.pack <$> getLine
  lrs <- map (map read . words) . lines <$> getContents :: IO [[Int]]
  let ans = map (\i ->LBS.index s i == 'A' && LBS.index s (i+1) == 'C') [0..LBS.length s - 1]
  forM_ lrs $ \[l, r] -> do
    let ans' =  take (r - l) (drop (l-1) ans)
    putStrLn . show . length $ filter (== True) ans'
