import Control.Monad
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.IntMap as IntMap

type Map = IntMap.IntMap Int

readIntsLine :: IO [Int]
readIntsLine = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

solve :: String -> String -> Int -> Int -> Map -> Map
solve [] _ _ _ m = m
solve (s:ss) prev step count m = solve ss [s] (step + 1) nextcount nextmap
  where nextcount = if prev ++ [s] == "AC" then count + 1 else count
        nextmap = IntMap.insert step nextcount m

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  s <- getLine
  let m = solve s "" 1 0 IntMap.empty
  replicateM_ q $ do
    [l, r] <- readIntsLine
    let lcount = fromMaybe 0 $ IntMap.lookup l m
    let rcount = fromMaybe 0 $ IntMap.lookup r m
    print $ rcount - lcount