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

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

    int q, l, r, res;
    string s;

	cin >> s >> q;
    s = s + "e";

    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        res = 1;

        for (int j = l - 1; j < r - 1; j++) {
            if (s[j + 1] < s[j]) res++;
        }

        cout << res << "\n";
    }

    cout << endl;
}
