#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    long long q;
    cin>>q;
    while(q--)
    {
        long long n, m, k=0;
        cin>>n>>m;
        for(int i=n-1; i<m-1; i++)
        {
            if(s[i]>s[i+1]) {k++;}  //cout<<s[i]<<' '<<s[i+1]<<' ' ;}
        }
        cout<<k+1<<endl;
    }
}
