'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 answer = [];
	for(let i=0;i<Q;i++){
		const li = parseInt(temp[i+2].split(' ')[0]);
		const ri = parseInt(temp[i+2].split(' ')[1]);

		const before = S.slice(li-1,ri);
		let count = before.length;
		const after = before.replace(/AC/g,'');

		console.log(Math.floor((before.length-after.length)/2));
	}

}

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