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;
  for(i=0;i<Q;i++){
    l_r = input_text[i+2].split(' ');
    l = l_r[0];
    r = l_r[1];
    S_substring = S.substring(l,r+1);
    for(j=0;j<S_substring.length-1;j++){
      if(S_substring[j] === 'A' || S_substring[j+1] === 'C'){
        count++;
      }
    }
    console.log(count);
    count=0;
  }
}
 
Main(require("fs").readFileSync("/dev/stdin","utf-8"));