#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    int n,q;
    string s;
    cin >> n >> q >> s;
    vector<int> cnt(n,0);
    repi(i,n,1){
        if(s[i-1] == 'A' && s[i] == 'C')cnt[i]++;
        cnt[i] += cnt[i - 1];
    }
    repi(i,q,0){
        int l,r;
        cin >> l >> r;
        l--;
        r--;
        cout << cnt[r] - cnt[l] << endl;
    }
    return 0;
}
/*
ID: hafiz.i1
TASK: milk2
LANG: C++
*/
#include<bits/stdc++.h>

#define ll long long
#define debug(x) cout<<x<<"DE"<<endl;

using namespace std;



int main()
{
//    freopen("milk2.in", "r", stdin);
//    freopen("milk2.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,q;
    cin>>n>>q;ll l[n+1];l[1]=0,l[0]=0;
    string s;
    cin>>s;
    for(int i=2;i<=n;i++){
        if(s[i-2]=='A'&&s[i-1]=='C')l[i]=l[i-1]+1;
        else l[i]=l[i-1];
    }
    for(int i=1;i<=q;i++){
        ll a,b;
        cin>>a>>b;
        cout<<l[b]-l[a]<<endl;
    }
}
