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

bool f(string s, long long i, long j)
{
	if (s[i]=='c'&&s[j]!='c') return true;
	if(s[i]=='b'&&s[j]=='a') return true;
	else return false;
}

int main()
{
	string s;
	cin >> s;
	s = "0" + s;
	long long q;
	cin >> q;
	vector<long long>a(2 * q + 1);
	long long 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))r++;
		cout << r+1 << endl;
	    r = 0;
	}
	system("pause");
}