function main(input) {
  var sp = input.split("\n");
  var spLength = sp.length;
  var NQ = sp[0].split(" ");
  var N = Number(NQ[0]);
  // var NLengthHalf = N / 2;
  var Q = NQ[1];
  var S = sp[1];

  // NまでのACの配列
  var arr = [];
  for(i=1; i<=N; i++){
    var tmp = S.substring(0, i);
    arr.push(countAC(tmp));
  }

  for(j=2; j<spLength-1; j++){
    var lr = sp[j].split(" ");
    var l = lr[0];
    var r = lr[1];

    console.log(arr[r-1]-arr[l-1]);
  }
}

function countAC(str){
  return str.split("AC").length - 1;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
