input = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
T = input[0].split(" ");
N = Number(T[0]);
Q = Number(T[1]);
S = input[1];
ans = "";
for(i = 2; i < Q + 2; i++){
    J = input[i].split(" ");
    m = Number(J[0])-1;
    M = Number(J[1]);
    B = S.substring(m,M);
    a = B.match(new RegExp("AC", "g"));
    if(a == null) a = 0;
    else a = a.length;
    if(i == 2) ans += a;
    else ans += "\n"+a;
}
console.log(ans)