import Control.Monad
import Data.List
import Data.Vector.Unboxed (Vector,(!))
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as B

main = do
  [_,q] <- readIntsLn
  s <- getLine
  let c = solve s
  replicateM q $ do
    [l,r] <- readIntsLn
    print $ c!r - c!l

solve :: String -> Vector Int
solve = U.fromList . (0:) . f 0 where
  f a ('A':'C':s) = a : (a+1) : f (a+1) s
  f a (c:s) = a : f a s
  f _ [] = []

readIntsLn
  = unfoldr (B.readInt . B.dropWhile(==' ')) <$> B.getLine