'use strict';
 
function Main(input) {
  var str_list = input.split('\n');
  var q_count = str_list.length - 2;
  var s_str = str_list[1];
  for (var i = 0; i < q_count; i++) {
    var val_list = str_list[q_count+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 >= 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());