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

string inp_str;

char cast(char inp) {
	switch (inp)
	{
	case 'a':
		return 1;
	case 'b':
		return 2;
	case 'c':
		return 3;
    }
}

unsigned int calc(unsigned int a, unsigned int b)
{
	char last_char = -1;
	char cur_char = -1;
	unsigned int itr = 1;

	for (unsigned int i = a - 1; i < b; i++)
	{
		cur_char = cast(inp_str[i]);
		if (last_char != -1 && cur_char < last_char) {
			itr++;
		}
		last_char = cast(inp_str[i]);
	}
	return itr;
}

int main() {
	ios_base::sync_with_stdio(0);

	cin >> inp_str;
	
	int n, a, b;
	cin >> n;

	for (unsigned int i = 0; i < n; i++)
	{
		cin >> a;
		cin >> b;
		cout << calc(a, b) << endl;
	}
	return 0;
}