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