#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;

    int a[q][2];
    for (int i = 0; i < q; ++i) {
        cin >> a[i][0];
        cin >> a[i][1];
        int words = 0;
        for (int j = a[i][0]; j < a[i][1]; ++j) {
            words += ((int)s[j-1] > (int)s[j]);
        }
        cout << words+1 << endl;
    }
}
