import Control.Monad
import Data.Array.IO

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 <- getLine
    e <- newArray (1,n) 0
    a <- accumACIndices 0 1 e s
    r <- replicateM q $ solve a
    mapM_ print r

accumACIndices :: Int -> Int -> IOArray Int Int -> String -> IO (IOArray Int Int)
accumACIndices _ n arr []           = return arr
accumACIndices c n arr ('A':'C':ls) = do
    let c' = c+1
    ar <- accumACIndices c' (n+2) arr ls
    writeArray ar n c'
    writeArray ar (n+1) c'
    return arr
accumACIndices c n arr (_:ls)       = do
    ar <- accumACIndices c (n+1) arr ls
    writeArray ar n c
    return arr

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