import Control.Monad
import Data.Bool
import Data.List

readInt = readLn :: IO Int
readInts = map read . words <$> getLine :: IO [Int]
readNInts = flip replicateM readInts

main :: IO ()
main = do
  [_, q] <- readInts
  s <- getLine
  lr <- readNInts q
  mapM_ print $ g lr $ f s

f :: String -> [Int]
f = f' 0
  where
    f' :: Int -> String -> [Int]
    f' n [_] = [n]
    f' n ('A':'C':xs) = n : n + 1 : f' (n + 1) xs
    f' n (x:xs) = n : f' n xs

g :: [[Int]] -> [Int] -> [Int]
g [] _ = []
g ([l, r]:lr) xs = xs !! (r - 1) - xs !! (l - 1) : g lr xs