'use strict'

function Main(input){
	let temp = input.trim().split('\n');
	const N = parseInt(temp[0].split(' ')[0]);
	const Q = parseInt(temp[0].split(' ')[1]);
	const S = temp[1];

	const ac = new Array(N);
	let count = 0;
	ac[0]=0;
	for(let i=1;i<N;i++){
		if((S[i-1]+S[i])=='AC') count++;
		ac[i] = count;
	}
	//console.log(ac);
	const answer = new Array(Q);
	for(let i=0;i<Q;i++){
		let li = parseInt( temp[i+2].split(' ')[0] )-1;
		let ri = parseInt( temp[i+2].split(' ')[1] )-1;
		//console.log(ri,li,ac[ri],ac[li])
		answer[i] = ac[ri] - ac[li] ;
	}

	console.log(answer.join('\n'));

}

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