#include <iostream>
#include <bits/stdc++.h>

#define int long long
#define endl '\n'
#define inf 2000000000000000000
#define random (rand()^(rand()<<15))

using namespace std;
constexpr int mod=1000000007;
constexpr int MOD=998244353;

void solve()
{
    string s;
    cin>>s;
    int q;
    cin>>q;
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        l--;r--;
        int res=1;
        char a='a';
        for(int i=l;i<=r;i++)
        {
            res+=(s[i]<a);
            a=s[i];
        }
        cout<<res<<endl;
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t=1;
//    cin>>t;
    for(int _=1;_<=t;_++)
    {
        solve();
    }
}
