"use strict";
    
const main = arg => {
    const N  = parseInt(arg.split("\n")[0].split(" ")[0]);
    const Q  = parseInt(arg.split("\n")[0].split(" ")[1]);
    const S  = arg.split("\n")[1].split("");
    //const lr = arg.split("\n").slice(2, N + 1);
    let dp = [0, 0];
    let cnt = 0;
    
    for(let i=2; i<=N; i++) {
        if(S[i-2] === "A" && S[i-1] === "C") {
            dp.push(dp[i-1] + 1);
        } else {
            dp.push(dp[i-1]);
        }
    }

    for(let i=0; i<Q; i++) {
        let l = parseInt(arg.split("\n")[i+2].split(" ")[0]);
        let r = parseInt(arg.split("\n")[i+2].split(" ")[1]);
        
        console.log(dp[r]-dp[l]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
