function Main(input) {
    // console.log(input);
    
    const N = parseInt(input[0].split(" ")[0]);
    const Q = parseInt(input[0].split(" ")[1]);
    const S = input[1];
    
    var ctArr = new Array(N);

    var count = 0;
    ctArr[0] = 0;
    for(var i = 1; i < N; i++) {
        if(S[i-1] == "A" && S[i] == "C") {
            count++;
        }
        ctArr[i] = count;
    }

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

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));
