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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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