#include <bits/stdc++.h>
using namespace std;

int main() 
{
 long long n,m,a[100001],b[100001],c[100001],i,j,k;
 string s;
 cin >> s;
 cin >> n;
 for(i=1;i<=s.length();i++)
 c[i]=int(s[i-1]);
 for(i=1;i<=n;i++)
 {
 cin >> a[i] >> b[i];
 k=1;
 for(j=a[i]+1;j<=b[i];j++)
 {
 if(c[j]<c[j-1]) 
 k=k+1;   
 }
 cout << k << endl;
 }
}
