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

int a [20010];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = (int) s.size () - 1;
    for (int i = 0; i < n; ++i) a[i] = s[i] > s[i + 1];
    for (int i = 1; i < n; ++i) a[i] += a[i - 1];
    int q, l, r;
    cin >> q;
    while (q--) {
        cin >> l >> r, --l, --r;
        if (l == r) {
            cout << "1 \n";
            continue;
        }
        int res = a[r - 1];
        if (l > 0) res -= a[l - 1];
        cout << res + 1 << '\n';
    }
}
