function Main(input) {
    const N = parseInt(input[0]);
    const Q = parseInt(input[1]);
    const S = input[2];
    
    var ctArr = 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);
    }

    var ret = "";
    for(var i = 0; i < Q; i++) {
        var l = input[i*2+3];
        var r = input[i*2+4];
        ret += ctArr[r-1] - ctArr[l-1] + "\n";
    }
    console.log(ret);
}

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