function Main(input){
	input = input.split("\n");
  var NQ = input.shift().split(" ").map(a=>~~a);
  var N = NQ[0];
  var Q = NQ[1];
  var S = input.shift();
  input = input.map(a=>a.split(" "));
  var l = input.map(a=>a[0]).map(a=>~~a);
  var r = input.map(a=>a[1]).map(a=>~~a);
  var result = Array(Q);
  for(var j = 0; j < Q ; j++){
  	result[j]=0;
  }
	 var debug = ""
  for(var i = 0; i < N - 1 ; i++){
  	var thisShouldA = S[i];
    var thisShouldC = S[i+1];
    debug += "\n" + thisShouldA + thisShouldC;
    if(thisShouldA==='A' && thisShouldC==='C'){
    	for(var j = 0; j < Q; j++){
      	if(i<l[j]-1)continue;
        if(r[j]-2<i)continue;
        result[j]+=1;
      }
    }
  }
  return result.join("\n");
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
8 3
ACACTACG
3 7
2 3
1 8
`);