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;
    foreach(i; 0..N) {
        input = readln().strip.split.to!(int[]);
        const s = input[0]-1;
        const g = input[1];
        writeln(S[s..g].count("AC"));
    }
}
