#include <bits/stdc++.h>

#define ll long long
#define us unsigned short
#define ui unsigned int

using namespace std;

int main() {
    string str;
    ui q, l, r;

    cin >> str >> q;

    for (int i=0; i < q; i++) {
        cin >> l >> r;
        int k = 1;
        for (int j=l+1; j < r; j++) {
            if (str[j] < str[j-1]) k++;
        }
        cout << k << '\n';
    }

    return 0;
}