
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B

import Debug.Trace (trace)

-- utility functions

--tr x = trace (show x) x
tr = id

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readCharV :: Int -> B.ByteString -> V.Vector Char
readCharV n = V.unfoldrN n f where
  f bs = Just (B.head bs, B.tail bs)

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

enumACPos xs = go xs 0 where
  go xs i
    | B.null xs = []
    | B.head xs == 'A' = go' (B.tail xs) (i+1)
    | otherwise = go (B.tail xs) (i+1)
  go' xs i
    | B.null xs = []
    | B.head xs == 'A' = go' (B.tail xs) (i+1)
    | B.head xs == 'C' = (i-1) : go (B.tail xs) (i+1)
    | otherwise = go (B.tail xs) (i+1)

solv :: B.ByteString -> V.Vector (Int,Int) -> IO ()
solv s qs = V.forM_ qs $ print . solv1
  where
    acpos = enumACPos s
    solv1 (l,r) = length $ tr [ac|ac <- acpos, l-1<=ac && ac+1<=r-1]

main = do
  [n,q] <- map read . words <$> getLine :: IO [Int]
  s <- B.getLine
  qs <- readTsV q <$> B.getContents
  solv s qs
