#include <iostream>

using namespace std;

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

    cin >> data >> q;

    int l, r, result;
    while (q--){
        cin >> l >> r;
        --l, --r;

        result = 1;
        for (int i = l + 1; i <= r; ++i){
            if (data[i] < data[i - 1]){
                result++;
            }
        }
        cout << result << endl;
    }
}