process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});

reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
  var NQ = lines[0].split(" ");
  var N = +NQ[0];
  var Q = +NQ[1];
  var S = lines[1];
  var l = new Array(Q);
  var r = new Array(Q);
  for(var i = 0; i<Q; i++){
    var lr = lines[i+2].split(" ");
    l[i] = +lr[0];
    r[i] = +lr[1];
  }
  
  var countAC = new Array(N);
  countAC[0] = 0;
  for(var i=1; i<N; i++){
	if(S[i-1]+S[i] == "AC") {
	  countAC[i] = countAC[i-1]+1;
	} else {
      countAC[i] = countAC[i-1];
    }
  }

  var ans = [];
  for(var i = 0; i<Q; i++){
	  ans.push(countAC[r[i]-1]-countAC[l[i]-1]);
  }
  console.log(ans.join("\n"));
});