void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], q = tmp[1];
    string s = readln.chomp;
    int[] dp = new int[n];
    foreach (i; 1 .. n) {
        int cnt;
        if (s[i-1] == 'A' && s[i] == 'C') {
            ++cnt;
        }
        dp[i] += dp[i-1] + cnt;
    }
    foreach (i; 0 .. q) {
        tmp = readln.split.to!(int[]);
        int l = tmp[0] - 1, r = tmp[1] - 1;
        writeln(dp[r] - dp[l]);
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;