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

int main() {
    string s;
    long long q, l, r, c;
    cin >> s;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        c = 1;
        for (int j = l - 1; j < r; j++) {
            if (j != l - 1) {
                if (s[j-1] > s[j]) c++;
                //cout << s[j-1] << " " << s[j] << endl;
            }
        }
        cout << c << endl;
    }
}
