{-# 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 -> if LBS.index s i == 'A' && LBS.index s (i+1) == 'C' then 1 else 0) [0..LBS.length s - 1] :: [Int]
  let ans' = scanl (+) 0 ans
  forM_ lrs $ \[l, r] -> do
    putStrLn . show $ ans' !! (r-1) - ans' !! (l -1)
