//https://atcoder.jp/contests/abc122/tasks/abc122_c
function setUp(input) {
  input = input.split("\n");
  N = Number(input[0].split(" ")[0]);
  Q = Number(input[0].split(" ")[1]);
  S = input[1];
  lList = input.slice(2, 2 + Q);
  lList = lList.map(function (d, i) {
    var arr = d.split(' ');
    return [Number(arr[0]) - 1, Number(arr[1]) - 1];
  })
  main();
}
function main() {
  ruiseki = [0];
  sLength = S.length;
  count = 0;
  for (var i = 0; i < sLength; i++) {
    var target = S[i] + S[i + 1];
    if (target === 'AC') {
      count++
    }
    ruiseki.push(count);
  }
  lList.forEach(function (d, i) {
    console.log(ruiseki[d[1]] - ruiseki[d[0]]);
  })
}
setUp(require("fs").readFileSync("/dev/stdin", "utf8"));
// setUp('8 3\nACACTACG\n3 7\n2 3\n1 8')