function myout(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var strLen = parseInt(input[0].split(" ")[0]);
  var qLen = parseInt(input[0].split(" ")[1]);
  
  var str = input[1];
  for(var i = 0; i < qLen; i++){
    var left = parseInt(input[i + 2].split(" ")[0]);
    var right = parseInt(input[i + 2].split(" ")[1]);
    var tmp = str.slice(left - 1, right);
    var mat = tmp.match(/AC/g);
    if(mat == null){
       mat = [];
       }
    myout(mat.length);
  }
  
}

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