#include <iostream>

using namespace std;

int main() {
    string str;
    int k;
    cin >> str >> k;
    while(k != 0) {
        int n1, n2, sum=0;
        cin >> n1 >> n2;
        n1--;

        for(; n1 < n2; n1++) {
            char c1 = str[n1], c2 = str[n1+1];
            if(c1 == 'c' && (c2 == 'a' || c2 == 'b') || c1 == 'b' && c2 == 'a')
                sum++;
            else if(n1+1 == n2)
                sum++;
        }
        cout << sum << '\n';
        k--;
    }
}