import Control.Applicative
import Control.Monad as M

solve :: String -> [[Int]] -> [Int]
solve str ns = map (\[p, q] -> solve' str p q) ns

solve' :: String -> Int -> Int -> Int
solve' str l r = f $ drop (l-1) $ take r str

f :: String -> Int
f str = g str 0 where
  g :: String -> Int -> Int
  g "" n = n
  g ('A':'C':xs) n = g xs (n+1)
  g (x:xs) n = g xs n
   
main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  str <- getLine
  ns <- M.replicateM q $ map read . words <$> getLine
  putStrLn $ concatMap (\i -> show i ++ "\n") (solve str ns)
