import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char

toTuple :: B.ByteString -> (Int, Int)
toTuple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, _) = B.readInt $ B.dropWhile isSpace bs'
    in
        (a, b)

step :: (Bool, Int) -> Char -> (Bool, Int)
step (b, c) x
    | x == 'A' = (True, c)
    | b && (x == 'C') = (False, c+1)
    | otherwise = (False, c)

main = do
    [n,q] <- map read . words <$> getLine
    xs <- VU.fromList . B.unpack <$> B.getLine :: IO (VU.Vector Char)
    fts <- VU.replicateM q (toTuple <$> B.getLine) :: IO (VU.Vector (Int, Int))
    let xs' = VU.map snd $ VU.scanl' step (False,0) xs
    VU.forM_ fts $ \(f,t) -> do
        print $ (xs' VU.! t) - (xs' VU.! f) 