{-# LANGUAGE OverloadedStrings #-} 
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.Text as T
import qualified Data.Map.Strict as Map
import Data.Maybe


createACMap :: T.Text -> Int -> Map.Map Int Int
createACMap t len =  Map.fromList $ snd indexAndCount  where
    indexAndCount = mapAccumL (\(acc, str) i -> if isIndexPrefixOfAC i str 
                                         then ((acc+1, T.drop 1 str), ((i+1),acc+1)) 
                                         else ((acc, T.drop 1 str) ,((1+i), acc))) 
                    (0, t) [1..len] 
    isIndexPrefixOfAC i str = T.isPrefixOf "AC" $ T.take 2 str


solve :: Map.Map Int Int -> Int -> Int -> Int
solve acMap from to = findVal to - findVal from
    where
        findVal i = fromMaybe 0 $ Map.lookup i acMap

main = do
    (len, lines) <- readTuple :: IO (Int, Int)
    s <- T.pack <$> getLine 
    let acMap = createACMap s len
    lrlist <- replicateM lines readTuple
    forM_ lrlist $ \(l, r) ->
        print $ solve acMap l r


readLs :: Read a => IO [a]
readLs = fmap read . words <$> getLine

readTuple :: Read a  => IO (a, a)
readTuple = do
    [f, s] <- readLs
    pure (f, s)