function Main(input){
  
  var str = input.trim().split("\n");
  var nq = str[0].split(" ");
  var n = nq[0];
  var q = nq[1];
  var s = str[1];
  var lr = str;
  lr.splice(0,2);
  
  //console.log("l:"+lr[0].split(" ")[0]);
  //console.log("l:"+lr[0].split(" ")[1]);  
  
  var kekka = 0;


  for(i=0;i<q;i++){
      var kaisu = 0;
    var tmps = s.substring(lr[i].split(" ")[0]-1,lr[i].split(" ")[1]);
    
    var index_a = tmps.indexOf("A");
             //console.log("index_a:"+index_a );  
                // console.log("tmps.length:"+tmps.length );  
    while(tmps.length>1){
    if(index_a !==-1)
    {tmps = tmps.slice(index_a);
                  //console.log("if inexa!==-1:"+index_a );  
              //console.log("tmps:"+tmps);      
              //console.log("tmps.slice(1,2):"+tmps.slice(1,2)); 
     if(tmps.slice(1,2)=="C"){
       tmps = tmps.slice(2);
        kaisu++;
               // console.log("tmps:"+tmps);  
         //console.log("kokokitayo");  
        }//if a next c
     else {
              tmps = tmps.slice(1);
     }//else
     
      
    }//if a detekureba
    else if(index_a == -1){
            tmps = "";
              //console.log("owaridayo");  
                     // console.log("tmpsend:"+tmps);  
            
            }// if a ga detekonai
    
    
  }//wihle end
    console.log(kaisu);
  }//for end i q 
  
  
  

  
  
}//function end
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));