function main(input) {
  const tmp = input.split(/\n/);
  const target = tmp[1];
  const indexList = [];
  var start = 0;
  while (true) {
    const index = target.indexOf("AC", start);
    if (index < 0) {
      break;
    } else {
      indexList[index] = index;
      start = index + 1;
    }
  }

  tmp.slice(2).forEach(str => {
    const nums = str.split(/\s/);
    const result = indexList
      .slice(Number(nums[0]) - 1, Number(nums[1]) - 1)
      .filter(num => !isNaN(num));
    console.log(result.length);
  });
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
