#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	string s;
	cin >> s;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int a, b, kol = 1;
		cin >> a >> b;
		for (int j = a + 1; j < b; j++) {
			if (int(s[j - 1]) > int(s[j])) {
				kol++;
			}
		}
		cout << kol << endl;
	}
}
