function main(input) {
    var inputs = input.split('\n');
    var N = parseInt(inputs[0].split(' ')[0], 10);
    var Q = parseInt(inputs[0].split(' ')[1], 10);
    var S = inputs[1];
    var lengths = [];
    for (var idx = 2; idx < 2 + Q; idx++) {
        lengths.push({
            begin : inputs[idx].split(' ')[0], 
            end   : inputs[idx].split(' ')[1]
        });
    }
    
    var results = [];
    for (var length of lengths) {
        var target = S.slice(length.begin, length.end);
        if (target.match(/AC/g)) {
           results.push(target.match(/AC/g).length);
        } else {
            results.push(0);
        }
    }

    for (var result of results) {
        console.log(result);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));