module Main where

import Control.Monad
import Data.List
import Data.List.Split
import Data.Array.IO
import qualified Data.Vector as V

main :: IO ()
main = do
  [n,q] <- map read . words <$> getLine
  s <- getLine
  lrs <- replicateM q $ map read . words <$> getLine :: IO [[Int]]

  let mi = minimum $ map (\(l:_) -> l) lrs
      ma = maximum $ map (\(_:m:_) -> m) lrs
      as = getS mi ma s

  mapM_ (\(l:r:_) -> (print . length . filter (\i -> i >= l && i < r)) as) lrs

solve (l:r:_) = getS l r

getS l r s = f (drop (l - 1) (take r s)) l []
  where
    f [] _ c = c
    f [_] _ c = c
    f (s1:s2:ss) i c | s1 == 'A' && s2 == 'C' = f ss (i + 2) (c ++ [i])
                     | otherwise = f (s2:ss) (i + 1) c