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 as = map (`solve` s) lrs

  mapM_ print as

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

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