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

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

    var target = S.substring(l-1, r);
    // AC -> *
    var zzz = target.replace(/AC/g, "*");
    // AC以外消す
    zzz = zzz.replace(/[^*]/g, "");
    console.log(zzz.length);
  }
}

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

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