#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"I=lambda:map(int,input().split());n,q=I();s=input();a=[0]\n"
"for i in range(n):a+=[a[i]+(s[i-1:i+1]=='AC')]\n"
"while q:l,r=I();print(a[r]-a[l]);q-=1\n"
"\"";
  system(s);
  return 0;
}            