{-# LANGUAGE OverloadedStrings #-} 
module Main where

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


createACMap :: T.Text -> Int -> [Int]
createACMap t len = filter (\i -> T.isPrefixOf "AC" $ T.drop (i-1) t) [1..len-1]

solve :: [Int] -> (Int, Int) -> Int
solve acMap (from, to) = length $ takeWhile (\pos -> pos < to) $ dropWhile (\pos -> pos < from) acMap

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


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

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