#include <iostream>

using namespace std;
string s;
long long q,i,j,l,r,c;
int main()
{
    cin>>s;
    cin>>q;
    for(i=0;i<q;i++){
        cin>>l>>r;
        c=0;
        for(j=l-1;j<r;j++){
            if(s[j]=='a'){
                if(j==r-1&&s[j]<s[j-1]){
                    c++;
                    continue;
                }
            }
            else if(s[j]=='b'){
                if(j==r-1&&s[j]<s[j-1]){
                    c++;
                    continue;
                }
                if(s[j+1]=='a')c++;
            }
            else {
                if(j==r-1){
                    c++;
                    continue;
                }
                if(s[j+1]=='c')continue;
                else c++;
            }
        }
        cout<<c<<endl;
    }
    return 0;
}

