#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, q;
	string s;
	cin >> n >> q >> s;
	vector<int> a(n);
	for (int i = 1; i < n; i++) {
		a[i] = a[i - 1] + (s[i - 1] == 'A' && s[i] == 'C' ? 1 : 0);
	}

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

