#include <iostream>

using namespace std;

int main()
{
    string abc;
    cin >> abc;
    long long m[20000];
    long long h=0;

    for(long long i=0; i<abc.length()-1; i++)
    {
        if((abc[i]=='b' and abc[i+1]=='a') or (abc[i]=='c' and abc[i+1]=='a') or (abc[i]=='c' and abc[i+1]=='b'))
        {
            m[h]=i;
            h++;
        }
    }
    long long q, l, r, sum;
    cin >> q;
    for(long long i=0; i<q; i++)
    {
        cin >> l >> r;
        sum=0;
        for(long long i1=0; i1<h; i1++)
        {
            if(m[i1]+1>=l and m[i1]+1<r)
            {
                sum++;
            }
        }
        cout << sum+1 << " ";
    }
    return 0;
}
