#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define st string
#define pb push_back
#define rt return
#define rv reverse
#define sr sort
#define si size()
#define en end()
#define be begin()
#define sc second
#define fr first
#define vl vector < ll >
#define vvl vector < vector < ll > >
#define vs vector < st >
#define vvs vector < vector < st > >
#define pall pair < ll , ll >
#define pasl pair < st , ll >
#define pals pair < ll , st >
using namespace std;

int main()
{
    fast;
    st s;
    cin >> s;
    ll a[s.si];
    a[0]=1;
    for (int i=1;i<s.si;++i)
    {
        a[i]=a[i-1];
        if (s[i-1]>s[i])
            ++a[i];
    }
    ll f;
    cin >> f;
    while (f--)
    {
        ll l,r;
        cin >> l >> r;
        if(l==1)
            cout << a[r-1] << "\n";
        else
            cout << a[r-1] - a[l-1]+1 << "\n";
    }

}
