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 . dropWhile (>= r) . takeWhile (>= l) $ ms
  where ms = myIndex s

myIndex :: String -> [Int]
myIndex s = snd $
  foldl (\(n,b,acc) c -> if c == 'A'
    then (n+1, True, acc)
    else if c == 'C' && b
         then (n+1, False, n:acc)
         else (n+1, False, acc)) (1, False, []) s

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