#include <iostream>

using namespace std;

string s;
long long n,res,r,l;

int main()
{
    cin>>s;
    cin>>n;
    for(int t=1; t<=n; t++){
        cin>>l>>r;
        res=0;
        for(int i=l-1; i<r-1; i++){
            if(s[i]>s[i+1])res++;
        }
        cout<<res+1<<endl;
    }
    return 0;
}
