'use strict';

function Main(input) {
  const reg = /AC/
  const N = input.split("\n")[0].split(" ")[0]
  const Q = input.split("\n")[0].split(" ")[1]
  const S = input.split("\n")[1]
  const Qlist = input.split("\n").slice(2)
    .map(x => x.split(" "))
    .map(x => [Number(x[0]), Number(x[1])])
  for (let Question of Qlist) {
    let piece = S.slice(Question[0]-1, Question[1])
    let answer = 0
    while (true) {
      if (piece.match(reg) === null) {
        break
      }
      piece = piece.slice(piece.match(reg).index+2)
      answer++
    }
    console.log(answer)
  }
};

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