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);
    ctArr[0] = 0;
    for(var i = 1; i < N+1; i++) {
        ctArr[i] = ctArr[i-1] + ((S[i-1] == 'A' && S[i] == 'C') ? 1 : 0);
    }

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