"use strict";
const main = input => {
    let n = input[0].split(' ')[0], q = input[0].split(' ')[1], 
    s = input[1], 
    l = new Array(q), r = new Array(q), count = new Array(n-1);
    for(let i=0; i<q; i++) {
        l[i] = input[i+2].split(' ')[0];
        r[i] = input[i+2].split(' ')[1];
    }
    for(let i=0; i<n-1; i++) {
        count[i] = 0
        if (s[i] == 'A' && s[i+1] == 'C') {
            count[i] = 1;
        }
    }    
    for(let i=0; i<q; i++) {
        let ans = 0;
        for(let k=l[i]; k<r[i]; k++) {
            if (count[k-1] == 1) {
                ans++;
            } 
        }
        console.log(ans);
        
    }
    // console.log(count);
    // console.log(s);
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));