#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	string s;
	int n,q,t,u;
	std::vector <int> a(0);
	cin >> n >> q>>s;
	a.push_back(0);
	for (int i = 1; i < n; ++i) {
		a.push_back((s.substr(i-1,2)=="AC")? a[i-1]+1:a[i-1]);
	}
	for (int i = 0; i < q; ++i) {
		cin >> t >> u;
		cout << a[u - 1] - a[t - 1] << "\n";
	}
	return 0;
}