#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s, s_copy;
    cin>>s;
    long q, l, r, answ;
    cin>>q;
    for(long i=0; i<q; i++){
        cin>>l>>r;
        answ = 1;
        s_copy = s;
        for(long j=l; j<r; j++){
            if((long)s_copy[j] >= (long)s_copy[j-1]){
                continue;
            }
            else{
                answ++;
                s_copy[j] = 'a';
            }
        }
        cout<<answ<<'\n';
    }
    return 0;
}
