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

int a[300000];
int res[300000];
int main() {
	string s1;
	cin >> s1;
	int n;
	cin >> n;
	int max = 0;
	for (int t = 0; t < s1.length(); t++) {
		a[t] = max;
		if (s1[t] > s1[t + 1]) {
			max++;
		}
	}
	for (int t = 0; t < s1.length(); t++)cout<<a[t]<<' ';

	for (int i = 0; i < n; i++) {
		int l, k;
		int max = 0;
		cin >> l >> k;
		res[i] = a[k-1] - a[l-1]+1;
	}
	for (int i = 0; i < n; i++)cout << res[i]<<'\n';

	return 0;
}
