#include <iostream>
using namespace std;
typedef long long ll;
int N,Q;
string S;
ll A[100010],C[100010],AC[100010];

int main(){
    cin >> N >> Q >> S;
    for(int i=1;i<N;i++){
        if(S[i-1]=='A' && S[i]=='C') AC[i+1]++;
        AC[i+1] += AC[i];
    }
    int l,r;
    for(int i=0;i<Q;i++){
        cin >> l >> r;
        cout << AC[r]-AC[l] << endl;
    }
}