import std.functional,
       std.algorithm,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;


void main() {
  int[] NQ = readln.chomp.split.to!(int[]);
  int N = NQ[0],
      Q = NQ[1];
  string s = readln.chomp;
  alias LR = Tuple!(int, "l", int, "r");
  LR[] lrs;
  lrs.length = Q;
  int[] dp;
  dp.length = N;

  foreach (i; 0..Q) {
    int[] lr = readln.chomp.split.to!(int[]);
    lrs[i] = tuple(lr[0], lr[1]);
  }

  for (size_t i = 1; i < s.length; i++) {
    if (s[i] == 'C' && s[i - 1] == 'A') {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = dp[i - 1];
    }
  }

  foreach (lr; lrs) {
    writeln(dp[lr.r - 1] - dp[lr.l - 1]);
  }
}