#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define mp make_pair
#define pb push_back

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

constexpr int INF = (int)1e18;
constexpr int N = (int)2e5 + 111;
constexpr int md = (int)998244353;

int pref[N];

void solve(){
    string s;
    cin >> s;
    int n = s.size();

    s = "d" + s;

    cerr << "0 ";
    for(int i = 1; i <= n; i++){
        pref[i] = pref[i-1] + (s[i] < s[i-1]);
        cerr << (s[i] < s[i-1]) << " ";
    }
    cerr << "\n";

    int q;
    cin >> q;
    while(q--){
        int l,r;
        cin >> l >> r;
        if(l == r){
            cout << "1\n";
            continue;
        }
//        l--,r--;
        cout << pref[r] - pref[l] + 1 << "\n";
    }

    return;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int tests = 1;
//    cin >> tests;
    for(int test = 1; test <= tests; test++){
        solve();
    }
    return 0;
}
/**
make VUDOI great again.

abcaabbaccccb
5
1 13
2 8
1 9
4 12
4 7

**/
