"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];
    const A = 'A'.charCodeAt(0);
    let S = lines.shift().split(/\s/)[0].split('').map((v) => v.charCodeAt(0) - A);
    let ans = new Array(Q).fill(0);
    for (let n = 0; n < Q; n++) {
        const nums = lines.shift().split(/\s/).map((v) => v - 0);
        for (let m = nums[0]-1; m < nums[1]-1; m++) {
            if (S[m] == 0 && S[m + 1] == 2) ans[n] ++;
        }
    }
    console.log(ans.join('\n'));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
