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 (V.fromList s)

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

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

getS :: Int -> Int -> V.Vector Char -> [Int]
getS l r s = f (V.drop (l - 1) (V.take r s)) ((V.toList .  V.elemIndices 'A') s)
  where
    f _ [] = []
    f ss [c] | c >= length ss = []
    f ss (c:cs) | ss V.! c == 'A' && ss V.! (c + 1) == 'C' = (c + 1) : f ss cs
                | otherwise = f ss cs