function main(input) {
  const tmp = input.split(/\n/);
  const target = tmp[1];
  tmp.slice(2).forEach(str => {
    const nums = str.split(/\s/).map(s => ~~s);
    console.log(target.slice(nums[0] - 1, nums[1]).split(/AC/g).length - 1);
  });
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
