"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split("\n");

const firstLine = input[0].split(" ").map((val) => parseInt(val, 10));

const N = firstLine[0];
const Q = firstLine[1];

const S = input[1];

for (let i = 2; i < Q + 2; i++) {
  const line = input[i].split(" ").map((val) => parseInt(val, 10));
  const l = line[0];
  const r = line[1];

  const substr = S.substring(l - 1, r);

  console.log(substr.split("AC").length - 1);
}
