import Control.Monad                                                                                                                                  
                                                                                                                                                      
main :: IO ()                                                                                                                                         
main = do                                                                                                                                             
  [_,q] <- map read . words <$> getLine                                                                                                               
  s <- getLine                                                                                                                                        
  lrs <- replicateM q $ (\[x,y] -> (x,y)) . map read . words <$> getLine :: IO [(Int,Int)]                                                            
  forM_ lrs $ \(l,r) -> do                                                                                                                            
    let partS = drop (l-1) . take r $ s                                                                                                               
    print $ neighbour partS 0                                                                                                                         
                                                                                                                                                      
neighbour :: String -> Int -> Int                                                                                                                     
neighbour [] acc = acc                                                                                                                                
neighbour [_] acc = acc                                                                                                                               
neighbour (x:y:xs) acc                                                                                                                                
  | [x,y] == "AC" = neighbour (y:xs) (acc + 1)                                                                                                        
  | otherwise = neighbour (y:xs) acc