#include <iostream>

using namespace std;

int main()
{
    int n,x,y,k;
    string s;
    cin >> s;
    cin >> n;
    for (int i=1; i<=n; ++i)
    {
        k=1;
        cin >> x >> y;
        for (int j=x-1; j<=y-2; ++j)
        {
            if (s[j]>s[j+1])
                k=k+1;
        }
        cout << k << endl;
    }

    return 0;
}
