function Main(input){
  input_text = input.split('\n');
  N_Q = input_text[0].split(' ');
  N = N_Q[0];
  Q = N_Q[1];
  S = input_text[1];
  count = 0;
  AC_Array = [];
  for(k=0;k<N-1;k++){
    if(S[k] === 'A' && S[k+1] === 'C'){
      AC_Array.push(k);
    }
  }
  console.log(AC_Array);
  for(i=0;i<Q;i++){
    l_r = input_text[i+2].split(' ');
    l = l_r[0]-1;	//index
    r = l_r[1]-1;	//index
    AC_Array.forEach((num)=>{
      if(l <= num && num < r){
        count++;
      }
    });
    console.log(count);
    count=0;
  }
}
 
Main(require("fs").readFileSync("/dev/stdin","utf-8"));