import           Control.Monad
import           Data.List
import           Data.List.Split
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM

create :: String -> V.Vector Int
create x = V.fromList $ f x 0
  where
    f [_] i = [i]
    f (s1:s2:ss) i
      | s1 == 'A' && s2 == 'C' = i:f (s2:ss) (i + 1)
      | otherwise = i:f (s2:ss) i

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  as <- create <$> getLine
  replicateM_ q
    $ do
      [l, r] <- map read . words <$> getLine
      print (as V.! (r - 1) - as V.! (l - 1))

