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-1);

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

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

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