#include <bits/stdc++.h>
#include <cstring>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	string n;
	cin>>n;
    int p;
    cin >>p;
    for(int i; i<p; i++){
        int l, r;
        cin >> l>>r;
        cout << l<< " "<<r<<"\n";
        string m;
        m = n.substr(l, r);
        string p1 = "cl";
        char p2 = p1[0];
        int slov = 1;

        for(int y; y>m.size(); y++){
            int qwf = m[y];
            int qws = p1[0];
            if(qwf<qws){
                slov+=1;
            }
            p2 = m[y];
        }
        cout << slov << "\n";
    }
}
