#include<bits/stdc++.h>

using namespace std;

#define endl '\n'
#define DIM 1003
#define INF 1000000009

long long n,a,b,k,kil;
string s;
int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> s;
    cin >> n;
    for(int i =1; i<=n; i++){
             k = 1;
       cin >> a >> b;
      for(int j=a; j<b; j++){

      if((s[j]=='a' && s[j-1]=='b') || (s[j]=='a' && s[j-1]=='c') ||(s[j]=='b' && s[j-1] == 'c')){k++;}

      }
       cout << k<<endl;
 }



  return 0;
}
