'use strict';

function Main(input) {
  const N = input.split("\n")[0].split(" ")[0]
  const Q = input.split("\n")[0].split(" ")[1]
  let S = input.split("\n")[1]
  const Qlist = input.split("\n").slice(2)
    .map(x => x.split(" "))
  const list = [0]
  let now = 0
  for (let i = 1; i < S.length-1; i++) {
    if (S[i-1] === "A" && S[i] === "C") {
      now++
    }
    list[i] = now
  }
  list[S.length-1] = now
  for (let Question of Qlist) {
    console.log(list[Question[1]-1] - list[Question[0]-1])
  }
};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
