import Control.Monad
import Data.Bool
import Data.List
import qualified Data.Vector as V

readInt = readLn :: IO Int
readInts = map read . words <$> getLine :: IO [Int]
readNInts = flip replicateM readInts

main :: IO ()
main = do
  [_, q] <- readInts
  s <- getLine
  lr <- readNInts q
  mapM_ print $ g lr $ f s

f :: String -> V.Vector Int
f = V.fromList . scanl (+) 0 . f'
  where
    f' :: String -> [Int]
    f' [] = []
    f' [_] = [0]
    f' ('A':'C':xs) = 0 : 1 : f' xs
    f' (x:xs) = 0 : f' xs

g :: [[Int]] -> V.Vector Int -> [Int]
g [] _ = []
g ([l, r]:lr) xs = (xs V.! r) - (xs V.! l) : g lr xs