function Main(input){
    a=input.split("\n");
    n=Number(a[0].split(" ")[0])
    q=Number(a[0].split(" ")[1])
    ans=[];
    mystring=a[1];
    for(i=0;i<q;i++){
        console.log(countAc(mystring,Number(a[i+2].split(" ")[0]),Number(a[i+2].split(" ")[1])));
    }
}
function countAc(string,start,end){
    var target=string.slice(start-1,end);
    var target2=target.split("");
    var mycount=0;
    for(v=0;v<target2.length-1;v++){
        if(target2[v]=="A"&&target2[v+1]=="C"){
            mycount++;
            target2[v]=0;
            target2[v+1]=0;
        }
    }
    return mycount
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
