#include<bits/stdc++.h>
using namespace std;
string s;
int n,q,p[100010],qzh[100010],l,r;
int main() {
	scanf("%d%d",&n,&q);
	cin>>s;
	for(int i=0;i<s.size();i++)
	if(s[i]=='A'&&s[i+1]=='C')
	p[i+1]=1;
	for(int i=1;i<=n;i++)
	qzh[i]=qzh[i-1]+p[i];
	while(q--)
	{
		scanf("%d%d",&l,&r);
		printf("%d\n",qzh[r-1]-qzh[l-1]);
	}
}