import Control.Monad
import Data.Array.Unboxed

main = do
    [n, q] <- map read <$> words <$> getLine
    s      <- getLine
    lr <- forM [1..q] $ \i -> do
        [li, ri] <- map read <$> words <$> getLine
        return (li, ri)
    forM (solve n q s lr) $ \ret -> do
        putStrLn $ show ret

solve :: Int -> Int -> String -> [(Int, Int)] -> [Int]
solve n q s lr = map calc lr
  where
    calc (l, r) = sumArray ! r - sumArray ! l
    sumArray :: UArray Int Int
    sumArray = listArray (1, n) $ doit 0 s
    doit c s | length s == 1    = [c]
             | take 2 s == "AC" = c : doit (c + 1) (tail s)
             | otherwise        = c : doit c (tail s)