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

int main() {
 

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

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

}

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

i=i+g+1;

}

cout<<answer<<endl;

}

}
