#include <iostream>
using namespace std;

int n, q, c, l, r;
char s[100010];
int k[100010];

int main(){
	cin >> n >> q;
	cin >> s;

	c = 0;
	k[0] = c;
	for (int i = 1; i < n; ++i){
		if (s[i-1] == 'A' && s[i] == 'C') c++;
		k[i] = c;
	}

	for (int i = 0; i < q; ++i){
		cin >> l >> r;
		cout << (k[r-1] - k[l-1]) << endl;
	}
}