import Control.Monad
import Data.Array

readPair :: Read a => IO (a,a)
readPair = do
    [a,b] <- map read . words <$> getLine
    return (a,b)

main = do
    (n,q) <- readPair :: IO (Int,Int)
    s <- listArray (1,n) . accumACIndices 0 <$> getLine
    r <- replicateM q $ solve s
    mapM_ print r

accumACIndices :: Int -> String -> [Int]
accumACIndices _ []           = []
accumACIndices c ('A':'C':ls) = let c'=c+1 in c':c':(accumACIndices c' ls)
accumACIndices c (_:ls)       = c:accumACIndices c ls

solve :: Array Int Int -> IO Int
solve arr = do
    (l,r) <- readPair
    let l' = if l > 1 then arr!(l-1) else 0
    return (arr!(r-1) - l')
