#include<bits/stdc++.h>
#define int long long
#define endl "\n";

using namespace std;

int bin_pow(int a, int b) {
	if(b == 0) return 1;
	if(b == 1) return a;
	if(b % 2 == 0) {
		int temp = bin_pow(a, b / 2);
		return temp*temp;
	} else {
		return bin_pow(a, b-1) * a;
	}
}

int gcd(int a, int b) {
	if(b == 0) return a;
	else {
		return gcd(b, a % b);
	}
}

signed main() {
	
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	
	string str;
	cin >> str;
	int len = str.length();
	
 	int k;
 	cin >> k;
 	
 	for(int i = 0; i < k; i++) {
 		int l, r;
 		cin >> l >> r;
 		r--;l--;
 		int count = 1;
 		for(int j = l+1; j <= r; j++) {
 			if(str[j] < str[j-1]) count++;
		 }
		 cout << count << endl;
	 }
	
	return 0;
}