#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
typedef long long ll;

const int nmax=200010;

tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ost;

int mas[nmax]={0};
int dp[nmax][2]={0};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n=s.size(),q,l,r;
    mas[0]=0;
    mas[1]=0;
    for(int i=1;i<n;i++) {
        mas[i+1]=bool(s[i]<s[i-1]);
    }
    for(int i=1;i<=n;i++) {
        mas[i]+=mas[i-1];
    }
    cin >> q;
    for(int i=0;i<q;i++) {
        cin >> l >> r;
        cout << mas[r]-mas[l]+1 << "\n";
    }
    return 0;
}
