#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;
string s;
ll l,r,n,k;
vector <ll> v;
int main(){
   //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
    cin >> s;
	cin >> n;
	while(n--){
		k = 1;
		cin >> l >> r;
	for(int i = l;i < r;i++){
		if(s[i] < s[i - 1])k++;
	}
	cout << k << endl;
}
  return 0;
}

