import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto nq = readints;
    int n = nq[0], q = nq[1];
    string s = read!string;

    // acc[i] = [0..1] までの AC の出現回数
    auto acc = new int[s.length];
    for (int i = 1; i < s.length; i++) {
        int x = s[i] == 'C' && s[i-1] == 'A';
        acc[i] = x + acc[i - 1];
    }

    foreach (_; 0..q) {
        auto lr = readints;
        int l = lr[0] - 1;
        int r = lr[1] - 1;

        int x = acc[r] - acc[l];
        writeln(x);
    }
}
