"use strict";
function Main(input) {
    let lines = input.split("\n");
    let nums = lines.shift().split(/\s/).map((v) => v - 0);
    let N = nums[0], Q = nums[1];
    let S = lines.shift().split(/\s/)[0].split('');
    for (let n = 0; n < Q; n++) {
        let nums = lines.shift().split(/\s/).map((v) => v - 0);
        let L = nums[0], R = nums[1];
        let ans = 0;
        for (let m = L-1; m < R-1; m++) {
            if (S[m] == 'A' && S[m + 1] == 'C') {
                ans++;
                m++;
            }
        }
        console.log(ans);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
