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

int f(string s, int i, int j)
{
	//i++;
	//j++;
	if (s[i] == 'a' && s[j] == 'b') return 1;
	if (s[i] == 'a' && s[j] == 'c') return 1;
	if (s[i] == 'b' && s[j] == 'c') return 1;
	if (s[i] == 'b' && s[j] == 'a') return 2;
	if (s[i] == 'c' && s[j] == 'b') return 2;
	if (s[i] == 'c' && s[j] == 'a') return 2;
	if (s[i] == s[j]) return 0;
}

int main()
{
	string s;
	cin >> s;
	s = "0" + s;
	long q;
	cin >> q;
	vector<int>a(2 * q + 1);
	int i, j, r = 0;
	for (i = 1; i <= q * 2; i++)
		cin >> a[i];
	for (i = 1; i <= 2 * q; i = i + 2)
	{
		for (j = a[i]; j < a[i + 1]; j++)
			if (f(s, j, j + 1) == 2)r++;
		cout << r+1 << endl;
	    r = 0;
	}
	system("pause");
}