#include <iostream>
using namespace std;
long long q, test, l, r, i, k;
string s;
int main() 
{
	cin>>s>>q;
	for (test=1; test<=q; test++)
		{
		 cin>>l>>r;
		 k=1;
		 for (i=l; i<r; i++)
			if (s[i-1]!=s[i] && s[i-1]>s[i]) k++;
		 cout<<k<<endl;
		}
	return 0;
}