#include <iostream>
using namespace std;
int main()
{
    string sent;
    cin>>sent;
    int n,start,end,max,res;
    cin>>n;
    for (int i=0;i<n;++i){
        cin>>start>>end;
        --start;
        end;
        max=0;
        res=1;
        for(int j=start; j<end; ++j){
            if(sent[j]=='a' && max<=1)
                max=1;
            else if(sent[j]=='b' && max<=2)
                max=2;
            else if(sent[j]=='c' && max<=3)
                max=3;
            else {
                res+=1;
                switch(sent[j]){
                    case 'a':
                        max=1;
                        break;
                    case 'b':
                        max=2;
                        break;
                    case 'c':
                        max=3;
                        break;
                }
            }
        }
        cout<<res<<endl;
    }
    return 0;
}
