function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var Q = parseInt(input[0].split(" ")[1]);
  var S = input[1];

  var l = Array(input.length-3);
  var r = Array(input.length-3);

  for(var i = 2; i < input.length-1; i ++){
    l[i-2] = parseInt(input[i].split(" ")[0]);
    r[i-2] = parseInt(input[i].split(" ")[1]);
  }

  var AtCoder = function(){};

  AtCoder.prototype = {
    procedure: function(){
      for(i = 0; i < l.length; i ++){
        console.log(S.substring(l[i]-1,r[i]).split("AC").length -1);
      }
    }
  }
  var atcoder = new AtCoder();
  atcoder.procedure();
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
