#include <bits/stdc++.h>
using namespace std;
const long long MOD=10e9+7;
#define Std 100003
#define StdD 100007
#define StdINF 1000000007
#define endl "\n"
#define ll long long
#define ull unsigned long long
#define ld long double
#define st string
#define ch char
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define sl set<ll>
ll n,sum,L,R,res;
st s;
void poshyk()
{
    for(int i=L-1;i<R-1;i++)
    {
        if(s[i]>s[i+1])
        {
            res++;
        }
    }
    cout<<res<<endl;
}
void Start()
{
    cin>>s;
    cin>>n;
    for(int i=1;i<=n;i++)
        {
            res=1;
            cin>>L>>R;
            poshyk();
        }

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

    return 0;
}
