{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, q ] <- readInts
	s <- getLine
	[ ls, rs ] <- transpose <$> replicateM q readInts
	let
		psum =  scanl (+) 0 $ detect_ac s
	mapM_ print $ solve psum ( map ( subtract 1 ) ls ) rs

detect_ac [] = []
detect_ac [_] = [ 0 ]
detect_ac (a:b:s)
	| a == 'A' && b == 'C' = 0 : 1 : detect_ac s
	| otherwise = 0 : detect_ac (b:s)

solve psum ls rs = runST $ do
	let
		n = length psum - 1
		q = length ls
	psum_a <- newArray ( 0, n + 1 ) 0 :: ST s ( STUArray s Int Int )
	forM ( zip [ 0 .. ] psum ) $ \( i, a ) -> do
		writeArray psum_a i a
	res <- newSTRef []
	forM ( zip ls rs ) $ \( l, r ) -> do
		a <- readArray psum_a $ l + 1
		b <- readArray psum_a r
		modifySTRef res ( b - a : )
	modifySTRef res reverse
	readSTRef res