import std.stdio, std.range, std.conv, std.string, std.array, std.functional;
import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting;
import std.container.binaryheap;

void main()
{
    auto input = readln().strip.split.to!(int[]);
    const N = input[0];
    const Q = input[1];
    const S = readln().strip;

    ulong[] list;
    list.length = S.length;
    char pc = S[0];
    foreach(i; 1..S.length) {
        char c = S[i];
        if(pc=='A' && c == 'C')
        {
            list[i] = list[i-1]+1;
        }else{
            list[i] = list[i-1];
        }
        pc = c;
    }

    foreach(i; 0..Q) {
        input = readln().strip.split.to!(int[]);
        const s = input[0]-1;
        const g = input[1]-1;
        writeln(list[g] - list[s]);
    }
}
