#include <bits/stdc++.h>

using namespace std;

#define DIM 20007

string s;
int n,q,l,r;
int d[DIM];

char pc;

int main(){

    cin >> s;
    n=s.size();

    d[n]=1;
    pc=s[n-1];

    for(int i=n-1; i>0; i--){
        d[i]=d[i+1];

        if(s[i-1]=='c' && pc=='b') d[i]++;
        if(s[i-1]=='c' && pc=='a') d[i]++;
        if(s[i-1]=='b' && pc=='a') d[i]++;

        pc=s[i-1];
    }

    cin >> q;
    for(int i=1; i<=q; i++){
        cin >> l >> r;
        cout << d[l]-(d[r]-1) << endl;
    }

    return 0;
}
