input = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
T = input[0].split(" ");
N = Number(T[0]);
Q = Number(T[1]);
S = input[1].split("");
ans = "";
SS = new Array(N);
for(i = 0; i < N; i++){
    SS[i] = (i === 0) ? 0 : SS[i-1];
    if(S[i] === 'A'){
        if(S[i+1] === "C"){
            i++;
            SS[i] = SS[i-1]+1;
        }
    }
}
for(i = 2; i < Q + 2; i++){
    J = input[i].split(" ");
    m = Number(J[0])-1;
    M = Number(J[1])-1;
    a = SS[M]-SS[m];

    if(i == 2) ans += a;
    else ans += "\n"+a;
}
console.log(ans)