'use strict';

function Main(input) {
    input = input.split("\n");
    const tmp = input[1].split("");
    let lastA = false;
    let count = 0;
    const acarray = tmp.map(x => {
        if (x === "C" && lastA) {
            count++;
            return count;
        }
        if (x === "A") {
            lastA = true;
            return count;
        }
        lastA = false;
        return count;

    });
    const question = input.slice(2);
    for (const q of question) {
        const qv = q.split(" ").map(x=>parseInt(x) - 1);
        console.log(parseInt(acarray[qv[1]] - acarray[qv[0]],10));
    }
    console.log();

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));