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 output = [];
  var str = input[1].split("");
  input.shift();
  input.shift();
  //累積和の集合
  var ACList = [];
  var count = 0;
  ACList.push(0);
  for(var i = 0; i < str.length - 1; i++){
    if(str[i] == "A" && str[i+1] == "C"){
      count++;
    }
    ACList.push(count);
  }
  for(var i = 0; i < qLen; i++){
    var left = input[i].split(" ")[0] - 1;
    var right = input[i].split(" ")[1] - 1;
    output.push(ACList[right] - ACList[left]);
  }
  myout(output.join("\n"));
}

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