"use strict";

const main = arg => {
    let rows = arg.trim().split("\n");
  	let N = rows[0].split(" ")[0]*1;
    let Q = rows[0].split(" ")[1];
    let S = rows[1].split("");
  
  	// 累積和を使うために分解していく
  	let ACNums = new Array(N).fill(0);
	for(let i = 1; i < N; i++){
    	if(S[i] == "C" && S[i - 1] == "A"){
        	ACNums[i] = ACNums[i - 1] + 1
        } else {
	        ACNums[i] = ACNums[i - 1]
        }
    }
  
  	// 書き出しの処理
  	let targetNums = rows.slice(2 , 2 + Q);
  	targetNums.forEach(
      (targetNum) => {
      	let s = targetNum.split(" ")[0] - 1;
        let g = targetNum.split(" ")[1] - 1;
        console.log(ACNums[g] - ACNums[s]);
      }
    )
}

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