import Control.Monad
import Data.Array

type Count = Int

readPair :: Read a => IO (a,a)
readPair = do
    [a,b] <- map read . words <$> getLine
    return (a,b)

main = do
    (n,q) <- readPair :: IO (Int,Int)
    s <- findACIndices 1 <$> getLine
    let ar = listArray (1,length s) s
    r <- replicateM q $ solveIO ar
    mapM_ print r


findACIndices :: Count -> String -> [Int]
findACIndices _ []           = []
findACIndices c ('A':'C':ls) = c:(findACIndices (c+2) ls)
findACIndices c (_:ls)       = findACIndices (c+1) ls

solveIO :: Array Int Int -> IO Int
solveIO ar = do
    p <- readPair
    return $ solve p ar

solve :: (Int,Int) -> Array Int Int -> Int
solve (l,r) arr = search r - search l 
    where search x = (binSearch arr (findLT x))


-- ## Algos ###

data Dir = L | R deriving (Show,Eq)

-- Binary search over {arr}, ranging from {l} to {r},
-- with the targeting logic {f}

binSearch :: Array Int a -> (Array Int a -> Int -> Dir) -> Int
binSearch arr = binSearchAux (bounds arr) arr
    where
        binSearchAux :: (Int, Int) -> Array Int a -> (Array Int a -> Int -> Dir) -> Int
        binSearchAux (l,r) arr f
            | l+1 >= r  = case (f arr l, f arr r) of
                (R,R) -> r+1
                (R,L) -> r
                (L,L) -> l
                (L,R) -> error "Erroneous targeting logic"
            | otherwise = let curPos = (l+r) `div` 2 in
                case f arr curPos of
                    L -> binSearchAux (l, curPos) arr f
                    R -> binSearchAux (curPos, r) arr f

---- # targeting logic

findLT :: Int -> Array Int Int -> Int -> Dir
findLT x arr n =
    if (arr!n) < x then R else L
