"use strict";
function Main(input) {
    let lines = input.split("\n");
    const nums = lines.shift().split(/\s/).map((v) => v - 0);
    const N = nums[0], Q = nums[1];
    let S = lines.shift().split(/\s/)[0] + 'x';
    let lr = new Array(Q);
    let ans = new Array(Q).fill(0);
    for (let n = 0; n < Q; n++) {
        lr[n] = lines.shift().split(/\s/).map((v) => v - 0 - 1);
    }
    let T = new Array(N).fill(0);
    for (let m = 0; m < S.length-1; m++) {
        T[m + 1] = T[m] + ((S.substr(m, 2) == 'AC') ? 1 : 0);
    }
    lr.forEach(function(v, i, a) {
        ans[i] = T[v[1]] - T[v[0]];
    });
    console.log(ans.join('\n'));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
