#include <stdio.h>
int main() {
    char s[20001];
    scanf("%s", s);
    int q;
    scanf("%d",&q);
    int i=0;
    while (i<q) {
        int sum=1;
        int l,r;
        scanf("%d %d",&l,&r);
        for (int j=l;j<r;++j) {
            if (s[j]<s[j-1]) ++sum;
        }
        printf("%d\n",sum);
        ++i;
    }
}