#include <bits/stdc++.h>
#include<iostream>

using namespace std;

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

    string s;
    int q, l, r, an = 1;
    cin >> s;
    cin >> q;
    int* ans = new int[q];
    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        for (int j = l; j < r; j++) {
            if (s[j] < s[j-1]) {
                an++;
            }
        }
        ans[i] = an;
        an = 1;
    }
    for (int i = 0; i < q; i++) {
        cout << ans[i] << '\n';
    }
}