import Control.Monad
import Data.Bool
import Data.List

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

main :: IO ()
main = do
  [_, q] <- readInts
  s <- getLine
  let sx = replicate q s
  lr <- readNInts q
  mapM_ (print . length) (fmap filterAC $ map allSubset $ dropNTake' lr sx)

filterAC = filter (=="AC")

allSubset :: [a] -> [[a]]
allSubset = concatMap inits . tails

dropNTake :: Int -> Int -> String -> String
dropNTake l r = drop (l - 1) . take r

dropNTake' :: [[Int]] -> [String] -> [String]
dropNTake' _ [] = []
dropNTake' ([l, r]:lrs) (x:xs) = dropNTake l r x : dropNTake' lrs xs