import           Control.Monad
import           Control.Monad.State
import qualified Data.ByteString.Char8       as B
import           Data.Char
import qualified Data.Vector.Unboxed         as U

readInt :: StateT B.ByteString Maybe Int
readInt = StateT $ B.readInt . B.dropWhile isSpace

main :: IO ()
main = do
  Just (n, q) <- evalStateT (liftM2 (,) readInt readInt) <$> B.getLine
  s <- U.fromListN n <$> getLine
  let sol = solve s
  forM_ [1 .. q] $ \_ -> do
    Just (l, r) <- evalStateT (liftM2 (,) readInt readInt) <$> B.getLine
    print $ sol U.! r - sol U.! l

solve :: U.Vector Char -> U.Vector Int
solve s = (0 `U.cons`)
  $ U.scanl (+) 0
  $ U.map (\x -> if x == ('A', 'C') then 1 else 0)
  $ U.zip s (U.drop 1 (s `U.snoc` '_'))
