'use strict'
function Main(input){
  input=input.trim().split(/\s+/);
  var N=input.shift()-0;
  var Q=input.shift()-0;
  var S='';
  var b=/A|T|G|C/;
  while(b.test(input[0]))
    S=S+input.shift();
  S=S.split('');
//  console.log(S);
  var T=[0,0];
  for(let i=1;i<N;i++)
    T[i+1]=T[i]+(S[i-1]==='A'&&S[i]==='C'?1:0);
//  console.log(T);
  var ans=[];
  for(let q=0;q<Q;q++){
    let l=input[2*q]-0,r=input[2*q+1]-0;
    ans[q]=T[r]-T[l];
  }
  console.log(ans.join('\n'));
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));