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] = 0;
    if(S[i] === 'A'){
        if(S[i+1] === "C"){
            i++;
            SS[i] = 1;
        }
    }
}
console.log(SS)
for(i = 2; i < Q + 2; i++){
    J = input[i].split(" ");
    m = Number(J[0]);
    M = Number(J[1]);
    a = 0;
    for(j = m; j < M; j++){
        a+=SS[j]
    }
    if(i == 2) ans += a;
    else ans += "\n"+a;
}
console.log(ans)