--{-# LANGUAGE OverloadedStrings #-}
--{-# LANGUAGE OverloadedLists   #-}
{-# LANGUAGE BangPatterns      #-} --引数に!
{-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE TupleSections     #-}

import Data.List
import Data.Tree
import Data.Array  --変数衝突
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Data.Graph
--import Data.Vector as V　--変数衝突
import qualified Data.Vector.Unboxed as V
import Control.Monad
import Control.Monad.State
import Control.Monad.ST

type DP s = STUArray s Int Int

f :: Int -> String -> [Int]
f _ [] = []
f i [_] = [i+1]
f i (c:d:s) = if (c,d) == ('A','C') then i : (f 0 s) else f (i+1) (d:s)
-- ??
g1 :: [Int] -> Int -> Int -> [Int]
g1 (k:s') l a = if l >= (a+k) then g2 s' l (a+k) else (k:s')

g2 :: [Int] -> Int -> Int -> [Int]
g2 s' l a = if l >= (a+2) then g1 s' l (a+2) else (0:s')


solve :: Int -> [Int] -> Int -> IO ()
solve _ _ 0 = return ()
solve n s' q = do
  [l,r] <- map read.words <$> getLine
  print $ (+(-1)) $ length $ g1 ( reverse $ g1 s' l 0) (n+1-r) 0
  solve n s' (q-1)

main :: IO ()
main = do
  [n,q] <- map read.words <$> getLine
  s <- getLine
  let s' = f 0 s
  solve n s' q
