#include <iostream>
#include <vector>

using namespace std;

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    int l, r;
    int res;
    for (int i = 0; i < q; i++)
    {
        cin >> l >> r;
        res = 0;
        for (int j = l; j <= r-1; j++)
            if ((s[j - 1] != 'a') and (s[j] == 'a'))
                res++;
            else
                if ((s[j - 1] == 'c') and (s[j] == 'b'))
                    res++;
        cout << res + 1 << endl;
    }
}
