'use strict';
 
function Main(input) {
  var str_list = input.split('\n');
  var nq_list = str_list[0].split(' ');
  var n_val = parseInt(nq_list[0]);
  var q_val = parseInt(nq_list[1]);
  var s_str = str_list[1];
  for (var i = 0; i < q_val; i++) {
    var val_list = str_list[q_val+i-1].split(' ');
    var l_number = val_list[0];
    var r_number = val_list[1];
    //create
    var tmp_str = '';
    for (var j in s_str) {
      if (j >= n_val || !s_str[j]) {
        break;
      }
      if (j >= l_number -1 && j < r_number) {
        tmp_str += s_str[j];
      }
    }
    console.log(tmp_str.split('AC').length-1);
  }
};
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
