#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long n, a, c, i, q, l, r;

string s;
int main()
{
cin>>s;


cin>>q;
while(q--){
    cin>>l>>r;
    c = 0;
    for(i=l-1; i<r-1; i++){
        if(s[i]>s[i+1]) c++;
    }
    cout<<c+1<<endl;
}

    return 0;
}
