import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto data = readln.split.to!(int[]);
	auto N = data[0], Q = data[1];
	auto S = readln.split[0];
	
	int[] _ACstarts;
	auto cnt = 0;
	while ( cnt < S.length-1 ) {
		if (S[cnt] == 'A') {
			if (S[++cnt] == 'C') _ACstarts ~= cnt-1;
			else --cnt;
		} 
		++cnt;
	}
	auto ACstarts = _ACstarts.assumeSorted();
	
	int[] ls, rs;
	foreach (i; 0 .. Q) {
		data = readln.split.to!(int[]);
		ls ~= data[0]-1, rs ~= data[1]-1;
	}
	
	foreach (i; 0 .. Q) {
		auto l = ls[i], r = rs[i];
		ACstarts.upperBound(l-1).lowerBound(r).length.writeln;
	}
	
}