#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;
    int q;
    cin >> q;
    vector<pair<long long, long long>>qandr;
    qandr.resize(q);
    vector <long long > a;
    long long l;
    long long r;
    for (int i = 0; i < q; i++)
    {
        cin >> l;
        cin >> r;
        qandr.push_back(pair<long long,long long>(l, r));
    }
    
    for (int i = 0; i < s.size(); i++)
    {
        a.push_back((int)s[i]);
    }
    
    for (int i = 0; i < q; i++)
    {
        int count = 0;
        qandr[i].first;
        qandr[i].second;
        for (int p = qandr[i].first; p <= qandr[i].second; i++)
        {
            if (!(a[p] == a[p + 1] || a[p] + 1 == a[p + 1] || a[p] + 2 == a[p + 1]))
                count++;
        }
        cout << count;
    }
}
