import Control.Monad (replicateM)
import Data.List

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

ans :: String -> [Int] -> Int
ans s [l,r] = length . filter (isPrefixOf "AC") $ tails s_
  where s_ = (drop (l-1) . take r) s

getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine