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

int main() {
    string s;
    cin>>s;
    int q;
    cin>>q;
    while (q--){
        int l, r;
        cin>>l>>r;
        if (l==r){
            cout<<1<<endl;
        }
        else {
            int result = 1;
            for (int i = l; i<r; i++){
                if (s[i] < s[i-1]){
                    result++;
                }
            }
            cout<<result<<endl;
        }
    }
}
