#include <bits/stdc++.h>
using namespace std;

int main() {
 

	string s;
	cin>>s;
    unsigned short a[20000];
  
    for(unsigned short i=1; i<=s.length(); i++) {
        a[i]=s[i-1];
       // cout<<a[i]<<" ";
    }
unsigned short q;
cin>>q;
for(unsigned short k=1; k<=q; k++) {
unsigned short l,r, answer=0;
cin>>l>>r;

unsigned short g=0;
unsigned short i=l;
while(i<=r)
{
    unsigned short g=0;
while(a[i+g+1]>=a[i+g]) {
    g++;

}

answer++;
//cout<<" "<<i<<" "<<answer<<" "<<g<<endl;

i=i+g+1;

}

cout<<answer<<endl;

}

}
