import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long Q, string S, long[] l, long[] r) {
    auto acc = new long[](N);
    auto s = S.array;
    foreach (i; 0 .. N - 1) {
        acc[i + 1] = acc[i];
        if (s.startsWith("AC"))
            acc[i + 1]++;
        s.popFront;
    }

    foreach (li, ri; zip(l, r)) {
        writeln(acc[ri - 1] - acc[li - 1]);
    }
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long Q;
    Q = input.front.to!long;
    input.popFront;

    string S;
    S = input.front.to!string;
    input.popFront;

    long[] l = new long[](cast(size_t) (Q));
    long[] r = new long[](cast(size_t) (Q));
    foreach (i; 0 .. cast(size_t) (Q)) {
        l[i] = input.front.to!long;
        input.popFront;
        r[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, Q, S, l, r);
    else
        solve(N, Q, S, l, r).writeln;
}
