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

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

	string data; cin >> data;

    int c; cin >> c;

    for (int q = 0; q < c; ++q) {
        int s, f; 
        cin >> s >> f; 
        s--; f--;

        int a = 1, l = 'a';
        for (int i = s; i <= f; ++i) {
            if (data[i] < l) {
                a++;
            }

            l = data[i];
        }
        cout << a << '\n';
    }

    return 0;
}
