#pragma GCC optimize("-Ofast","-funroll-all-loops") #include<bits/stdc++.h> //#define int long long using namespace std; const int N=1e6+10; int n,f[N],q; char str[N]; int find(int x){return x==f[x]?x:f[x]=find(f[x]);} signed main(){ cin>>n>>q; scanf("%s",str+1); for(int i=1;i<=n+1;i++) f[i]=i; for(int i=1,l,r,res;i<=q;i++){ scanf("%d %d",&l,&r); res=0; int now=find(l); while(now<=r){ if(str[now]=='A') res++; now=f[now]=find(now+1); } printf("%d\n",res); } return 0; }