{-# 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) `LBS.snoc` ' '
    let ixs = LBS.elemIndices 'A' s'
    putStrLn . show . length . filter (== True) $  map (\i -> LBS.index s' (i+1) == 'C') ixs
