import Control.Monad (replicateM)
import qualified Data.Map.Strict as M

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 n) lrs

ans :: String -> Int -> [Int] -> Int
ans s n [l,r] = (ms !! (n-r)) - (ms !! (n-l))
  where ms = myIndex s

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

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