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

int main() {
 
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
	string s;
	cin>>s;
    short a[20000];
  
    for(int i=1; i<=s.length(); i++) {
        a[i]=s[i-1];
       // cout<<a[i]<<" ";
    }
int q;
cin>>q;
for(int k=1; k<=q; k++) {
int l,r, answer=0;
cin>>l>>r;

int g=0;
int i=l;
while(i<=r)
{
    int g=0;
while((s[i+g+1]=='b' and s[i+g]=='a') or (s[i+g+1]=='c' and s[i+g]=='b') or (s[i+g+1]=='c' and s[i+g]=='a') or (s[i+g+1]=='a' and s[i+g]=='a') or (s[i+g+1]=='b' and s[i+g]=='b')  or (s[i+g+1]=='c' and s[i+g]=='c')) {
    g++;

}

answer++;
//cout<<" "<<i<<" "<<answer<<" "<<g<<endl;

i=i+g+1;

}

cout<<answer<<endl;

}

}
