{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad.State              (StateT (..), runStateT)
import           Data.Attoparsec.ByteString.Char8 (isSpace)
import qualified Data.ByteString.Char8            as B
import qualified Data.ByteString.Unsafe           as B
import qualified Data.Vector                      as V

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  s <- B.getLine
  lrs <- V.unfoldrN q parseInt2 <$> B.getContents
  mapM_ print $ solve n q s lrs

solve :: Int -> Int -> B.ByteString -> V.Vector (Int, Int) -> V.Vector Int
solve n _ s lrs = V.map (\(l, r) -> xs V.! (r - 1) - xs V.! (l - 1)) lrs
  where xs = V.scanl' (+) 0 $ V.generate (n - 1) ac
        ac i
          | B.index s i == 'A' && B.index s (i + 1) == 'C' = 1
          | otherwise = 0

parseInt :: B.ByteString -> Maybe (Int, B.ByteString)
parseInt = B.readInt . B.dropWhile isSpace

parseInt2 :: B.ByteString -> Maybe ((Int, Int), B.ByteString)
parseInt2 = runStateT $
  (,) <$> StateT parseInt
  <*> StateT (B.readInt . B.unsafeTail)
