const main = (input) => {
  const inputs = input.trim().split("\n");
  const N = Number(inputs[0].split(" ")[0]);
  const Q = Number(inputs[0].split(" ")[1]);
  const S = inputs[1];

  const map = [];
  var cnt = 0;
  for(var i=0;i<S.length;i++){
    if(S[i]=='C' && S[i-1]=='A'){
      cnt++;
    }
    map[i+1]=cnt;
  }


  for(var i=2;i<inputs.length;i++){
    var l = Number(inputs[i].split(" ")[0]);
    var r = Number(inputs[i].split(" ")[1]);
    console.log(map[r]-map[l]);
  }

}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));
