#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int q;
    unsigned short st;
    unsigned short e;
    int k;
    cin>>s;
    cin>>q;
    vector<unsigned short> prbl;
    for (unsigned short i=1;i<s.length();i++){
        if ((s[i]=='b' and s[i-1]=='c') or (s[i]=='a' and (s[i-1]=='b' or s[i-1]=='c'))){
            prbl.push_back(i);
        }
    }
    for (int i=0;i<q;i++){
        cin>>st;
        cin>>e;
        k=0;
        for (int pr=0;pr<prbl.size();pr++){
            if (st<=prbl[pr] and prbl[pr]<e){
                k++;
            }
        }
        cout<<k+1<<"\n";
    }
}
