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

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

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

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