import Control.Monad

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 <- findACIndices 1 <$> getLine
    r <- replicateM q $ solveIO s
    mapM_ print r


findACIndices :: Int -> String -> [Int]
findACIndices _ []           = []
findACIndices c ('A':'C':ls) = c:(findACIndices (c+2) ls)
findACIndices c (_:ls)       = findACIndices (c+1) ls

solveIO :: [Int] -> IO Int
solveIO ls = do
    p <- readPair
    return (length $ solve p ls)

solve :: (Int,Int) -> [Int] -> [Int]
solve (l,r) = dropWhile (<l) . takeWhile (<r)