function Main(input){
	input = input.split("\n");
  var NQ = input.shift().split(" ");
  var N = ~~NQ[0];
  var Q = ~~NQ[1];
  var S = input.shift();
  var lr = input;
  
  var sum = [0];
  
  for(var i = 1 ; i < N; i++){
  	var a = S[i-1];
    var c = S[i];
    if(a == 'A' && c == 'C'){
    	sum[i] = sum[i-1] + 1;
    }else{
    	sum[i] = sum[i-1];
    }
  }
  
  var r = "";
  
  for(var i = 0; i < Q; i++){
  	if(i!= 0)r+="\n";
  	var el = lr[i].split(" ");
    var ooo = ~~el[0];
    var fourze = ~~el[1];
    r += (sum[fourze-1]-sum[ooo-1]);
  }
  
  return r;
  
}

// 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
1 1
1 8
`);